Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#127 Cannot hanlde spaces at start of a string

open
nobody
None
5
2012-04-03
2012-04-03
Jos de Jong
No

json-lib cannot handle spaces at the start of a string:

String str = " {\"a\":123,\"b\":\"bla\"}";
JSONObject json = (JSONObject) JSONSerializer.toJSON(str);

will crash. I guess it has to do with the method JSONSerializer.toJSON(String string, JsonConfig jsonConfig):
...
if( string.startsWith( "[" ) ){
json = JSONArray.fromObject( string, jsonConfig );
}else if( string.startsWith( "{" ) ){
json = JSONObject.fromObject( string, jsonConfig );
...

Discussion