Convert a JSON string to object in Java ME?

前端 未结 14 946
有刺的猬
有刺的猬 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:02

    I used a few of them and my favorite is,

    http://code.google.com/p/json-simple/

    The library is very small so it's perfect for J2ME.

    You can parse JSON into Java object in one line like this,

    JSONObject json = (JSONObject)new JSONParser().parse("{\"name\":\"MyNode\", \"width\":200, \"height\":100}");
    System.out.println("name=" + json.get("name"));
    System.out.println("width=" + json.get("width"));
    

提交回复
热议问题