1
Vote

Possible parsing issue with JSON (IronPython + System.Net.Json)

description

I am running into a reproducible and mildly annoying problem, which I can't find any other references to online and assume it's a translation issue b/w the agDLR and Silverlight itself.
 
When parsing a JSON String via JsonArray or JsonObject (.Parse, but also attempted converting to a MemoryStream and running 'Load') I am getting "extra" quotes (Double quote - ") embedded in any Strings (JsonPrimitive, JsonType 'String').
 
I've tried a bunch of different things. Out of curiosity, if I change all double-quotes in the response string to single quotes, it still parses, and still includes "extra" double quotes inside. I am running lstrip('"').rstrip('"') against each string but it's rather annoying, and seems like a bug.
 
Example of a response string from my server (Python, simplejson, if it matters):
{"status_code": 200, "status_message": "Login OK.", "data_type": "LOGIN", "data": {"user_id": 1, "session_id": "a4a58718f5cde2561f362e315f08d116"}}
 
I run:
 
json_obj = JsonObject.Parse(responseString)
print "Parsed Json: %s" % json_obj
 
The ToString on the json_obj prints "correctly" - no extra quotes.
 
However:
 
json_obj['data_type'].ToString() or json_obj['data_type'] (The value itself being a JsonPrimitive of JsonType 'String'), always print out, etc. as:
 
'"LOGIN"'
 
This seems like it MAY be a agDLR issue, but I'm unsure.

file attachments

comments

spassig wrote Apr 1, 2009 at 1:26 PM

We have all kind of problems using the .NET JSON parser. Apart from those double quotes we ran into different conversion problems with all the .NET primitives types. If you just want to convert JSON to simple python arrays and dictionarys I would succest that you use simplejson (as we did). I attached a slightly modified version of simplejson (Version 2.0.7) (you also need the struct Modul) that works fine in our project. Simply copy the "stdlib" folder in your python folder of the chiron project, add a "sys.path.append("stdlib")" in your application and you can use simplejson.

wrote Apr 1, 2009 at 1:27 PM

bwmcadams wrote Apr 13, 2009 at 3:10 PM

Thanks, this is a huge help.
Decode works great, but encode is throwing errors for me in all cases. I tried a few of the samples from simplejsons' docs as well and same problems:


simplejson.dumps(['foo', {'bar': ('baz', None, 1.0, 2)}])
System.ArgumentNullException: Value cannot be null.
Parameter name: method
at <module> in <string>, line 0
at iterencode in stdlib/simplejson/encoder.py, line 252
at encode in stdlib/simplejson/encoder.py, line 197
at dumps in stdlib/simplejson/init.py, line 228
at <module> in <string>, line 0
=> None


Any thoughts?

wrote Feb 13, 2013 at 9:09 PM