Convert a JSON string to object in Java ME?

前端 未结 14 1116
有刺的猬
有刺的猬 2020-11-22 02:12

Is there a way in Java/J2ME to convert a string, such as:

{name:\"MyNode\", width:200, height:100}

to an internal Object representation of

14条回答
  •  天涯浪人
    2020-11-22 02:50

    Like many stated already, A pretty simple way to do this using JSON.simple as below

    import org.json.JSONObject;
    
    String someJsonString = "{name:"MyNode", width:200, height:100}";
    JSONObject jsonObj = new JSONObject(someJsonString);
    

    And then use jsonObj to deal with JSON Object. e.g jsonObj.get("name");

    As per the below link, JSON.simple is showing constant efficiency for both small and large JSON files

    http://blog.takipi.com/the-ultimate-json-library-json-simple-vs-gson-vs-jackson-vs-json/

提交回复
热议问题