JSONObject 遍历各个字段值

一般json串:

String Str = "{\"password\":\"123456\",\"username\":\"张三\"}";
JSONObject jsonObj = JSONObject.fromString(jsonStr);
String username = jsonObj.getString("username");
String password = jsonObj.optString("password");

嵌套json串:

JSONObject obj = {"code":"优","score":{"min":"90","max":"100"}} ;
String min= obj.getObject("score").getString("min");

你可能感兴趣的:(Java)