import java.util.Iterator;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
public class testOk {
public static void main(String[] args) {
String a = "{\"agreementAreas\":[{\"citys\":[{\"city\":\"441900\",\"cityName\":\"东莞市\"}],\"province\":\"440000\",\"provinceName\":\"广东省\"}],\"code\":\"0\"}";
JSONObject da = JSONObject.fromObject(a);
Iterator iterator = da.keys();
String key = null;
String value = null;
while (iterator.hasNext()) {
key = (String) iterator.next();
// System.out.println(key);
if (key.equals("agreementAreas")) {
JSONArray jsonArray = JSONArray.fromObject(da
.get("agreementAreas"));
JSONObject jsonObj = jsonArray.getJSONObject(0);
System.out.println(jsonObj);
StringBuilder sb = new StringBuilder();
Iterator bv = jsonObj.keys();
String keys = null;
String values = null;
while (bv.hasNext()) {
keys = (String) bv.next();
System.out.println(keys);
if (keys.equals("province")) {
value = jsonObj.getString(keys);
sb.append(value);
System.out.println(value);
}
if (keys.equals("provinceName")) {
values = jsonObj.getString(keys);
System.out.println(values);
sb.append(values);
}
System.out.println("StringBuilder:" + sb);
String as = jsonObj.getString("province");
String b = jsonObj.getString("provinceName");
JSONArray jsonArrayX = jsonObj.getJSONArray("citys");
}
}
}
}
}
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
public class testOk {
}