How i can get all the keys from a string which somehow looks like json string
I have a string like below
{"226167":"hawaiii","3193":"california"}
Can I use some java method 开发者_高级运维 to get all the key values (226167,3193 ) in a List object. If yes How it's done...?
String json = "{'226167':'hawaiii','3193':'california'}";
JSONObject object = (JSONObject) new JSONTokener(json).nextValue();
Iterator<String> yourKeys = object.keys();
for( String s : yourKeys)
System.out.println( s );
You need the JSON.Org library to run this (http://www.json.org/javadoc/org/json/JSONTokener.html)
Regards, Stéphane
精彩评论