简体   繁体   中英

How to get a value from a key value pair which is of type String?

I have a String as "{"result" : "27"}" how do I retrieve the value of 27 from the above string in java ? Your help would be appreciated thankyou !

Try this..

String string_type = "{\"result\" : \"27\"}";
JSONObject string_value = new JSONObject(string_type);
String result = string_value.getString("result");
Syatem.out.println("result :"+result);

try this,

JSONObject string_value = new JSONObject("{"result" : "27"}");
Syatem.out.println("result :"+string_value.getString("result"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM