how to parse unquoted JSON string

后端 未结 3 1337
孤独总比滥情好
孤独总比滥情好 2021-01-17 09:57

I have a JSON string where neither the keys nor the values are quoted and I would like to transform it to a correctly formatted JSON.

{basic:{0:{index:0, lice         


        
3条回答
  •  失恋的感觉
    2021-01-17 10:47

    Not sure if you got around to writing you own parser or not, but I did.

    https://github.com/ischumacher/rsjp

    Here is example usage with your example JSON:

    String str = "{basic:{0:{index:0, license:t, nameSID:n, image:\"img_left\", descriptionSID:t, category:r}}";
    Map jso = Json.parseJSON(str);
    System.out.println(jso);
    System.out.println(Json.get(jso, "basic", "0", "image"));
    

    Here is the output:

    {
       basic: 
       {
          0: 
          {
             index: 0, 
             license: t, 
             nameSID: n, 
             image: img_left, 
             descriptionSID: t, 
             category: r
          }
       }
    }
    
    img_left
    

提交回复
热议问题