Issue 92 in json-simple: bug in get(), ContainerFactory

8 views
Skip to first unread message

json-...@googlecode.com

unread,
Oct 25, 2013, 7:05:07 PM10/25/13
to json-...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 92 by Dominik....@googlemail.com: bug in get(), ContainerFactory
http://code.google.com/p/json-simple/issues/detail?id=92

Hello,

I have problems parsing the string:
{"multicast_id":5195543660248293070,"success":1,"failure":2,"canonical_ids":0,"results":[{"message_id":"0:1382740990960684%921c249af9fd7ecd"},{"error":"InvalidRegistration"},{"error":"InvalidRegistration"}]}

I'd like to have key=>value like:
success=>1
failure=>2
results=>[{"message_id":"0:1382740990960684%921c249af9fd7ecd"},{"error":"InvalidRegistration"},{"error":"InvalidRegistration"}]

But get("results") returns:
[{message_id=0:1382739363231902%921c249af9fd7ecd},
{error=InvalidRegistration}, {error=InvalidRegistration}]
As you see, the "" got lost and : became =

So I cannot continue parsing results to
0=>{message_id=0:1382739363231902%921c249af9fd7ecd}
1=>{error=InvalidRegistration}
2=>{error=InvalidRegistration}

Please test this function and try to find a solution:

public static void func()
{

String
str="{\"multicast_id\":5375760673945275273,\"success\":1,\"failure\":2,\"canonical_ids\":0,\"results\":[{\"message_id\":\"0:1382739363231902%921c249af9fd7ecd\"},{\"error\":\"InvalidRegistration\"},{\"error\":\"InvalidRegistration\"}]}";
System.out.println("original: "+str);

JSONParser parser = new JSONParser();
ContainerFactory containerFactory = new ContainerFactory(){
public List creatArrayContainer() {
return new LinkedList();
}


public Map createObjectContainer() {
return new LinkedHashMap();
}
};

try{
Map json = (Map)parser.parse(str, containerFactory);
System.out.println("wtf: " + json.get("results"));

/*
String res = json.get("results").toString();
JSONParser parser2 = new JSONParser();
Object obj=parser2.parse(res);
JSONArray array=(JSONArray)obj;
for(int a = 0; a < array.size(); a++)
System.out.println("results["+a+"] = "+array.get(a));
*/

}

catch(ParseException pe){
System.out.println(pe);
}
}

Thanks.

--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

json-...@googlecode.com

unread,
Jul 14, 2014, 11:15:26 PM7/14/14
to json-...@googlegroups.com
Updates:
Status: Invalid

Comment #1 on issue 92 by fangyid...@gmail.com: bug in get(),
ContainerFactory
http://code.google.com/p/json-simple/issues/detail?id=92

(No comment was entered for this change.)
Reply all
Reply to author
Forward
0 new messages