JSON格式错误,导致java.lang.RuntimeException

时间:2018-12-09 21:22:33

标签: java android json

我正在尝试使用android studio为whatsapp构建一个简单的贴纸应用。我不知道为什么它说有一个邮件格式的json文件。 这是logcat上的错误(可能是其他错误,例如apk的名称错误或其他错误)

D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.javiermilei.stickers, PID: 5574
    java.lang.RuntimeException: Unable to get provider com.javiermilei.stickers.StickerContentProvider: java.lang.RuntimeException: contents.json file has some issues: Use JsonReader.setLenient(true) to accept malformed JSON at line 17 column 10
        at android.app.ActivityThread.installProvider(ActivityThread.java:5923)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:5490)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5429)
        at android.app.ActivityThread.-wrap2(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1564)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6186)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
     Caused by: java.lang.RuntimeException: contents.json file has some issues: Use JsonReader.setLenient(true) to accept malformed JSON at line 17 column 10
        at com.javiermilei.stickers.StickerContentProvider.readContentFile(StickerContentProvider.java:149)
        at com.javiermilei.stickers.StickerContentProvider.getStickerPackList(StickerContentProvider.java:155)
        at com.javiermilei.stickers.StickerContentProvider.onCreate(StickerContentProvider.java:90)
        at android.content.ContentProvider.attachInfo(ContentProvider.java:1751)
        at android.content.ContentProvider.attachInfo(ContentProvider.java:1726)
        at android.app.ActivityThread.installProvider(ActivityThread.java:5920)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:5490) 
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5429) 
        at android.app.ActivityThread.-wrap2(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1564) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6186) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779) 
     Caused by: android.util.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 17 column 10
        at android.util.JsonReader.syntaxError(JsonReader.java:1159)
        at android.util.JsonReader.checkLenient(JsonReader.java:838)
        at android.util.JsonReader.nextInObject(JsonReader.java:660)
        at android.util.JsonReader.peek(JsonReader.java:349)
        at android.util.JsonReader.hasNext(JsonReader.java:319)
        at com.javiermilei.stickers.ContentFileParser.readStickers(ContentFileParser.java:145)
        at com.javiermilei.stickers.ContentFileParser.readStickerPack(ContentFileParser.java:106)
        at com.javiermilei.stickers.ContentFileParser.readStickerPacks(ContentFileParser.java:47)
        at com.javiermilei.stickers.ContentFileParser.parseStickerPacks(ContentFileParser.java:28)
        at com.javiermilei.stickers.StickerContentProvider.readContentFile

我找不到错误,因为文件应该在第17行第10列(根据logcat)存在邮件格式

{
  "android_play_store_link": "",
  "ios_app_store_link": "",
  "sticker_packs": [
    {
      "identifier": "1",
      "name": "Javier Milei",
      "publisher": "QBSLC Inc.",
      "tray_image_file": "tray_Milei.png",
      "publisher_email":"",
      "publisher_website": "",
      "privacy_policy_website": "",
      "license_agreement_website": "",
      "stickers": [
        {
          "image_file": "01_Milei.webp",
        },
        {
          "image_file": "02_Milei.webp",
        },
        {
          "image_file": "03_Milei.webp",
        },
        {
          "image_file": "04_Milei.webp",
        },
        {
          "image_file": "05_Milei.webp",
        },
        {
          "image_file": "06_Milei.webp",
        },
        {
          "image_file": "07_Milei.webp",
        },
        {
          "image_file": "08_Milei.webp",
        },
        {
          "image_file": "09_Milei.webp",
        },
        {
          "image_file": "10_Milei.webp",
        },
        {
          "image_file": "11_Milei.webp",
        },
        {
          "image_file": "12_Milei.webp",
        },
        {
          "image_file": "13_Milei.webp",
        }

      ]
    }
  ]
}

1 个答案:

答案 0 :(得分:2)

您可以检查JSON是否有效, 例如,使用以下网站:https://jsonformatter.curiousconcept.com/

在您的情况下,标签条目中的逗号无效。