开发者

How i can get all the keys from a string which somehow looks like json string

开发者 https://www.devze.com 2023-03-28 21:14 出处:网络
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 do

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

0

精彩评论

暂无评论...
验证码 换一张
取 消