简体   繁体   中英

What's Wrong With This JSON?

I'm using json simple to create and parse some json. However, after creating it, I then get a ParseException when I do parser.parse(jStr); . Below is the value of jStr

{"score":12,"balls":[[PURPLE_V,134.33325,331.11713,2.0,10.750022,-115,11.0,0],[PURPLE_SPLAT,59.209473,169.87143,0.0,6.2909174,16,11.0,1],[GREEN_V,119.00015,73.71671,-12.0,6.7500067,-35,11.0,0],[ORANGE_V,229.66664,7.4416676,8.0,5.250001,-5,11.0,0]]}

What's wrong with this? Can I not do an array of arrays?

PURPLE_VPURPLE_SPLATGREEN_VORANGE_V应该在引号内。

Try JSONLint :

{
    "score": 12,
    "balls": [
        [
            PURPLE_V,
            134.33325,
    // ..

output

Parse error on line 4:
...      [            PURPLE_V,          
----------------------^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', ']'

PURPLE_V , etc. are not recognized types. If you wanted them to be Strings, surround 'em with quotes.

The non-numeric values should be between quotation marks.

{"score":12,"balls":[["PURPLE_V",134.33325,331.11713,2.0,10.750022,-115,11.0,0],["PURPLE_SPLAT",59.209473,169.87143,0.0,6.2909174,16,11.0,1],["GREEN_V",119.00015,73.71671,-12.0,6.7500067,-35,11.0,0],["ORANGE_V",229.66664,7.4416676,8.0,5.250001,-5,11.0,0]]}

I recommend you to use http://jsonlint.com/ to validate your JSON. You might also want to check http://www.json.org/

Corrected (with also some formatting for viewing):

{"score":12,"balls":[
    ["PURPLE_V",134.33325,331.11713,2.0,10.750022,-115,11.0,0],
    ["PURPLE_SPLAT",59.209473,169.87143,0.0,6.2909174,16,11.0,1],
    ["GREEN_V",119.00015,73.71671,-12.0,6.7500067,-35,11.0,0],
    ["ORANGE_V",229.66664,7.4416676,8.0,5.250001,-5,11.0,0]
]}

See http://json.org

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM