如何解决JSON中的期望'STRING'错误

时间:2017-06-21 06:46:30

标签: android json getjson

我想在我的应用程序中使用 json Json 链接:Google JSON

但是当在https://jsonlint.com/中检查这个json时,请告诉我这个错误:

Error: Parse error on line 1:
{   predictions: [{         d
--^
Expecting 'STRING', '}', got 'undefined'

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

您必须输入proper JSON format

用你的例子:

{"prediction":[{"bla":1},{"blabla":2}]}

您的JSON的每个键都必须是字符串,因此是双引号。

编辑: 这是一个具有正确语法的JSON片段。



{
   "predictions" : [
      {
         "description" : "ورزشگاه آزادی, تهران, استان تهران, ایران",
         "id" : "f030ac8db2df64a9bd389b5c269be00409840c11",
         "matched_substrings" : [
            {
               "length" : 13,
               "offset" : 0
            }
         ],
         "place_id" : "ChIJvQwav4v8jT8RsME5g1S9_UA",
         "reference" : "CoQBgAAAAFECjj8o4B-jAZrNtY40NCaTH81J-XndLQ-P4kFuq3aEa29FZGgUcrbz0hHtunLebna-jpAh2ehtRC0eD1ulaHU8rtPseQyB28gcad1YcP7HYFMytycK6uweA5hFoO3tiANDv1tQHUCVCBxoai0TDZ04FkxY0FLwVc446zaPW14WEhA9-TzcUn_b8rA3bNWtlqOjGhQIfwx0iB7iVVLBPm0reMejSP9drg",
         "structured_formatting" : {
            "main_text" : "ورزشگاه آزادی",
            "main_text_matched_substrings" : [
               {
                  "length" : 13,
                  "offset" : 0
               }
            ],
            "secondary_text" : "تهران, استان تهران, ایران"
         },
         "terms" : [
            {
               "offset" : 0,
               "value" : "ورزشگاه آزادی"
            },
            {
               "offset" : 15,
               "value" : "تهران"
            },
            {
               "offset" : 22,
               "value" : "استان تهران"
            },
            {
               "offset" : 35,
               "value" : "ایران"
            }
         ],
         "types" : [ "establishment" ]
      },
      {
         "description" : "سینما آزادی, تهران, استان تهران, ایران",
         "id" : "5fb3c9e8466bb1a18edbbeed57235389984a8bdd",
         "matched_substrings" : [
            {
               "length" : 11,
               "offset" : 0
            }
         ],
         "place_id" : "ChIJFXH3RU8Bjj8RoCA94pB7PEU",
         "reference" : "CoQBfAAAAOH1U3WpwebFo65m6QeJwPkayOhWRo_cg4lXTBTfwfHnUcX2MDclxWHyHDwe4B5GJU-RcIE1juUWYVezu4Pxw_J-L4zs3pREK1ZtxVypaOyH0ENJVMPTJ8B4fr_g7HBTn25yxRdURiLB923xntwsF1UQeuNWBYDozdDmt3ti6-TLEhCoyPVYCLlcaQOREARuadr3GhRF6XUIor8fQBF58dxLxVjxRSiEaw",
         "structured_formatting" : {
            "main_text" : "سینما آزادی",
            "main_text_matched_substrings" : [
               {
                  "length" : 11,
                  "offset" : 0
               }
            ],
            "secondary_text" : "تهران, استان تهران, ایران"
         },
         "terms" : [
            {
               "offset" : 0,
               "value" : "سینما آزادی"
            },
            {
               "offset" : 13,
               "value" : "تهران"
            },
            {
               "offset" : 20,
               "value" : "استان تهران"
            },
            {
               "offset" : 33,
               "value" : "ایران"
            }
         ],
         "types" : [ "establishment" ]
      },
      {
         "description" : "برج آزادی, تهران, استان تهران, ایران",
         "id" : "341a8946768fa86f028ca90b5a2dca7f0417dd60",
         "matched_substrings" : [
            {
               "length" : 9,
               "offset" : 0
            }
         ],
         "place_id" : "ChIJkS4scwX-jT8R9BX9vhfAvvw",
         "reference" : "CoQBeQAAAH7QIxqxsYQYwKW9aGcFBFS0HKAmBRY9QSaGPAVZE0BLSkpQyKyDKY7MnOP5RIl5muluoyFlZC_heOeTHmnh9rZlHlwgiVVarSnagr3vteeD3ZAFWbpYe3Yz3ZmRuiwkkZl0cjfb19WkhVtFQFE90RXWnqgc3ri80TH-1VC8VOgkEhCy7RMS1kEyCDlUZ11Tpsp6GhQOwQ6c5bKa79NnvORHb1507ebs-g",
         "structured_formatting" : {
            "main_text" : "برج آزادی",
            "main_text_matched_substrings" : [
               {
                  "length" : 9,
                  "offset" : 0
               }
            ],
            "secondary_text" : "تهران, استان تهران, ایران"
         },
         "terms" : [
            {
               "offset" : 0,
               "value" : "برج آزادی"
            },
            {
               "offset" : 11,
               "value" : "تهران"
            },
            {
               "offset" : 18,
               "value" : "استان تهران"
            },
            {
               "offset" : 31,
               "value" : "ایران"
            }
         ],
         "types" : [ "establishment" ]
      },
      {
         "description" : "آزادی, تهران, استان تهران, ایران",
         "id" : "d1b450bcc251fdbc988f73dda82edee1c26b9ded",
         "matched_substrings" : [
            {
               "length" : 5,
               "offset" : 0
            }
         ],
         "place_id" : "EjnYotiy2KfYr9uMLCDYqtmH2LHYp9mGLCDYp9iz2KrYp9mGINiq2YfYsdin2YYsINin24zYsdin2YY",
         "reference" : "CnRnAAAAOa2un_nooAcX8DqkrTGAATrgaTGPFvMU9b0CIsgOOcheeEC1p6crUlogxuyIcAaSl_F3gEkFBHrjLGc_Hv5DI_VYGzRZzEt43p66H4TJO4u4DktgMpikv2LMRXruYelYcxN5B1BJA_E9FPjlkjo-xRIQUqTNt57jwTvWoGMueacfjBoU11gG1Wa-UmmYrd4IMn73nXX-8MQ",
         "structured_formatting" : {
            "main_text" : "آزادی",
            "main_text_matched_substrings" : [
               {
                  "length" : 5,
                  "offset" : 0
               }
            ],
            "secondary_text" : "تهران, استان تهران, ایران"
         },
         "terms" : [
            {
               "offset" : 0,
               "value" : "آزادی"
            },
            {
               "offset" : 7,
               "value" : "تهران"
            },
            {
               "offset" : 14,
               "value" : "استان تهران"
            },
            {
               "offset" : 27,
               "value" : "ایران"
            }
         ],
         "types" : [ "route", "geocode" ]
      },
      {
         "description" : "آزادی منش, Zeytoon Street, تهران, استان تهران, ایران",
         "id" : "389a7144ee3434df3cc7a1504df73e55cf3ce903",
         "matched_substrings" : [
            {
               "length" : 5,
               "offset" : 0
            }
         ],
         "place_id" : "ChIJOw-ir_L5jT8RYViiJk8Lkyo",
         "reference" : "CpQBiQAAADQjFMkeUtsnXsl1Hvbj6GpuGKT53jqIcHouGi8X-F9CZn6sE19NO_sJEgy1Zl7_IKcYnEEaFrSzfGvyclY7dem0b8UURVcHfcKfm-gn5bXc8wN2kdtp5TmRWHa8LMOnx3US85mygKGzwMztxGfisB1e2JcWtnFpyQGFsLyika279CNY_MhXyh_qhygfSicQ_RIQRazxTnLf3pVrdTGHhSl5ahoUQNSHgMD-ggRCZCcl3LcvU32PQSI",
         "structured_formatting" : {
            "main_text" : "آزادی منش",
            "main_text_matched_substrings" : [
               {
                  "length" : 5,
                  "offset" : 0
               }
            ],
            "secondary_text" : "Zeytoon Street, تهران, استان تهران, ایران"
         },
         "terms" : [
            {
               "offset" : 0,
               "value" : "آزادی منش"
            },
            {
               "offset" : 11,
               "value" : "Zeytoon Street"
            },
            {
               "offset" : 27,
               "value" : "تهران"
            },
            {
               "offset" : 34,
               "value" : "استان تهران"
            },
            {
               "offset" : 47,
               "value" : "ایران"
            }
         ],
         "types" : [ "establishment" ]
      }
   ],
   "status" : "OK"
}