Java解析Json循环遍历获取未知Key值
很多时候我们在解析Json的时候,一开始并不需要直接获取Value值,
而是得到这串Json数据的Key值,有些人就不知所措了
下面我们来看下Java中如何通过循环遍历获取Json数据中Key的方法
import net.sf.json.JSONObject;
String json = "{\"Url\":\"yunjson.com\"}";
JSONObject jsonObj = JSONObject.fromObject(json);
String name = jsonObj.getString("Url");
Iterator it = jsonObj.keys();
List<String> keyListstr = new ArrayList<String>();
while(it.hasNext()){
keyListstr.add(it.next().toString());
}