我有以下JSON字符串
String JSON = {"IP":{"string":"1.2.3.4"},"UrlParameters":{"map":{"pw":"36","mu":"www.abc.com"}}}
我需要在Java中获得pw和mu的值。我该如何解析它?
答案 0 :(得分:1)
你可以试试这个:
public static void main(String[] args) throws JSONException{
// TODO Auto-generated method stub
String JSON = "{\"IP\":{\"string\":\"1.2.3.4\"},\"UrlParameters\":{\"map\":{\"pw\":\"36\",\"mu\":\"www.abc.com\"}}}";
JSONObject jsonObject = new JSONObject(JSON);
System.out.println("Full JSON String: "+jsonObject);
JSONObject urlParametersMap = jsonObject.getJSONObject("UrlParameters").getJSONObject("map");
System.out.println("mu: "+urlParametersMap.getString("mu"));
System.out.println("pw: "+urlParametersMap.getString("pw"));
}