How to convert jsonString to JSONObject in Java

前端 未结 19 3035
一生所求
一生所求 2020-11-22 00:39

I have String variable called jsonString:

{\"phonetype\":\"N95\",\"cat\":\"WP\"}

Now I want to convert it into JSON Object. I

19条回答
  •  鱼传尺愫
    2020-11-22 01:27

    If you are using http://json-lib.sourceforge.net (net.sf.json.JSONObject)

    it is pretty easy:

    String myJsonString;
    JSONObject json = JSONObject.fromObject(myJsonString);
    

    or

    JSONObject json = JSONSerializer.toJSON(myJsonString);
    

    get the values then with json.getString(param), json.getInt(param) and so on.

提交回复
热议问题