Convert a JSON string to object in Java ME?

前端 未结 14 950
有刺的猬
有刺的猬 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条回答
  •  梦毁少年i
    2020-11-22 02:54

    The simplest option is Jackson:

    MyObject ob = new ObjectMapper().readValue(jsonString, MyObject.class);
    

    There are other similarly simple to use libraries (Gson was already mentioned); but some choices are more laborious, like original org.json library, which requires you to create intermediate "JSONObject" even if you have no need for those.

提交回复
热议问题