fansofdetective / json-simple

Automatically exported from code.google.com/p/json-simple
Apache License 2.0
0 stars 0 forks source link

parse simple json in JSONObject #78

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago

What steps will reproduce the problem?
1.
try {
    { 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(responce, containerFactory);
What is the expected output? What do you see instead?
could not convert to jsonObject

What version of the product are you using? On what operating system?
1.1.1

Please provide any additional information below.
i want to simple parse it to jsonObject .
the resone way is this i just want to manage order of the object 

Original issue reported on code.google.com by noman.iq...@purelogics.net on 18 Sep 2012 at 12:24

GoogleCodeExporter commented 9 years ago
Did you follow the following example? It should work.
http://code.google.com/p/json-simple/wiki/DecodingExamples#Example_4_-_Container
_factory

Original comment by fangyid...@gmail.com on 19 Sep 2012 at 2:20

GoogleCodeExporter commented 9 years ago
this example returns the map object but i need the jsonObject ... 

Original comment by noman.iq...@purelogics.net on 19 Sep 2012 at 4:57

GoogleCodeExporter commented 9 years ago
You mean instance of JSONObject? If it's the case, you can do something like:

Map jsonMap = <Map object return by JSONParaer>;
JSONObject jsonObject = new JSONObject(jsonObject);

Original comment by fangyid...@gmail.com on 19 Sep 2012 at 9:40

GoogleCodeExporter commented 9 years ago
JSONObject jsonObject = new JSONObject(jsonObject); 
this line will change the order of keys... 
that's y i want to use this simple class

Original comment by noman.iq...@purelogics.net on 19 Sep 2012 at 9:41

GoogleCodeExporter commented 9 years ago
Well, JSONObject is also a Map. May I ask why you need a JSONObject instead of 
a Map? I mean, if you just want to manipulate it and encode it to JSON string 
later, you can use JSONValue to encode the Map object directly:

http://code.google.com/p/json-simple/wiki/EncodingExamples#Example_1-3_-_Encode_
a_JSON_object_-_Using_Map

Original comment by fangyid...@gmail.com on 19 Sep 2012 at 3:46

GoogleCodeExporter commented 9 years ago

Original comment by fangyid...@gmail.com on 21 Sep 2012 at 3:20