How to convert jsonString to JSONObject in Java

前端 未结 19 3003
一生所求
一生所求 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:33

    To convert a string to json and the sting is like json. {"phonetype":"N95","cat":"WP"}

    String Data=response.getEntity().getText().toString(); // reading the string value 
    JSONObject json = (JSONObject) new JSONParser().parse(Data);
    String x=(String) json.get("phonetype");
    System.out.println("Check Data"+x);
    String y=(String) json.get("cat");
    System.out.println("Check Data"+y);
    

提交回复
热议问题