How to deserialize json string into object

后端 未结 4 2039
心在旅途
心在旅途 2021-01-23 06:07
{
   \"LocalLocationId [id=1]\":{
      \"type\":\"folderlocation\",
      \"id\":{
         \"type\":\"locallocationid\",
         \"id\":1
      },
      \"parentId\":         


        
4条回答
  •  执念已碎
    2021-01-23 06:43

    User JSONParser which is faster one.

    Below is sample. there can be a btter example if you google. Hope this helps.

    JSONParser parser=new JSONParser();
    System.out.println("=======decode=======");
    String s="[0,{\"1\":{\"2\":{\"3\":{\"4\":[5,{\"6\":7}]}}}}]";  
    Object obj=parser.parse(s);  
    JSONArray array=(JSONArray)obj;  
    System.out.println("======the 2nd element of array======");  
    System.out.println(array.get(1));  
    System.out.println();                  
    JSONObject obj2=(JSONObject)array.get(1);  
    System.out.println("======field \"1\"==========");  
    System.out.println(obj2.get("1"));                      
    s="{}";  
    obj=parser.parse(s);  
    System.out.println(obj);                  
    s="[5,]";  
    obj=parser.parse(s);  
    System.out.println(obj);                  
    s="[5,,2]";  
    obj=parser.parse(s);  
    System.out.println(obj);
    

提交回复
热议问题