我从如下服务器获取响应字符串
{ "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 );