我从服务器得到一个响应字符串,如下所示
{"name":"Json","detail":{"first_name":"Json","last_name":"Scott","age":"23"},"status":"success"}
我想得到名字的价值.我怎样才能做到这一点?提前致谢.
解决方法
看这个代码我在应用程序中使用了什么
String data="{'foo':'bar','coolness':2.0,'altitude':39000,'pilot':{'firstName':'Buzz','lastName':'Aldrin'},'mission':'apollo 11'}";
我这样检索
JSONObject json = (JSONObject) JSONSerializer.toJSON(data); double coolness = json.getDouble( "coolness" ); int altitude = json.getInt( "altitude" ); JSONObject pilot = json.getJSONObject("pilot"); String firstName = pilot.getString("firstName"); String lastName = pilot.getString("lastName"); System.out.println( "Coolness: " + coolness ); System.out.println( "Altitude: " + altitude ); System.out.println( "Pilot: " + lastName );