Parsing an Array of Json bug?
Monkey Forums/Monkey Programming/Parsing an Array of Json bug?
| ||
I'm not sure if this is a bug or not, but this json is valid:
Local json:String = "[{~qgame_id\~q: ~qsquares_inverted~q}]"
Local json:JsonObject = New JsonObject(json)
This will throw an uncaught monkey exception. Any ideas? Thanks! |
| ||
Ok, just in case anyone stumbles upon this same issue. I looked at source coude and problem is, brl.json is not fully compliant with json specification. At least in the case of a json that begins as an array such as:
[
{"greet":"Hello World"}
]
Anyway, the "right" way to send it will not cause that error:
{
"items": [
{
"greet": "Hello World"
}
]
}
I think this is standard since it's not common to send things in the way I was doing. Maybe that's why this bug slipped. |
| ||
| This should work: Local jsonArray:=JsonArray( New JsonParser( theJson ).ParseValue() ) The JsonObject constructor is really just a helper for creating json objects (not arrays) like this. Not actually sure why I didn't add one for arrays too - perhaps because it would've got a bit confusing when it came to JsonValue( str:String )...perhaps these should have been static ParseBlah() methods in JsonObject/JsonArray etc. |
| ||
| Hi Mark! Thanks for your reply. I think the array approach I was taking is bad anyway. Still, it's nice to know that It's not a bug and It can be done if you need to :) |