I am just getting started with some Jackson JSON data here. This section is giving me trouble.
"pointData":{
"1":"32.1093904, 66.7065216",
"2":"33.1236854, 67.8128443",
"3":"32.9524550, 67.0013501"
}
It seems to me that having integers as the attribute name is illegal. Is this correct?
You're correct that JSON cannot have integer attribute names, because all JSON attribute names must be quoted as yours are above, making them strings. See the flow here: http://json.org/
Also, your JSON structure above is invalid because it begins with an attribute name, but no object that the attribute is a part of. If you're getting errors, this is why. A legal structure would be:
{"pointData":{
"1":"32.1093904, 66.7065216",
"2":"33.1236854, 67.8128443",
"3":"32.9524550, 67.0013501"
}
}
FYI, if you're storing point data, a perhaps better structure would be:
{"pointData":{
"1": {"x": 32.1093904, "y": 66.7065216},
"2": {"x": 33.1236854, "y": 67.8128443},
"3": {"x": 32.9524550, "y": 67.0013501}
}
}
Notice two things about this structure:
x
and y
property that are independently accessible.x
and y
properties are numeric, not strings.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With