Convert a JSON string to object in Java ME?

前端 未结 14 916
有刺的猬
有刺的猬 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 03:11

    This is an old question and json-simple (https://code.google.com/p/json-simple/) could be a good solution at that time, but please consider that project seems not to be active for a while !

    I suggest the Gson which is now hosted at: https://github.com/google/gson

    If performance is your issue you can have a look at some benchmarks http://blog.takipi.com/the-ultimate-json-library-json-simple-vs-gson-vs-jackson-vs-json/ which compare.

    0 讨论(0)
  • 2020-11-22 03:14

    Just make a Json object in java with the following Json String.In your case

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

    if the above is your Json string , just create a Json Object with it.

    JsonString ="{name:"MyNode", width:200, height:100}";
    JSONObject yourJsonObject = new JSONObject(JsonString);
    System.out.println("name=" + yourJsonObject.getString("name"));
    System.out.println("width=" + yourJsonObject.getString("width"));
    
    0 讨论(0)
提交回复
热议问题