[英]Parse a JSON-string in Android
现在,我有以下JSON字符串:
“{” 1 “:{” 从 “:” 540" , “到”: “1020”}, “2”:{ “从”: “540”, “到”: “1020”}, “3”: { “从”: “540”, “到”: “1020”} “4”:{ “从”: “540”, “到”: “1020”}, “5”:{ “从”:” 540" , “到”: “1020”}, “6”:{ “从”: “540”, “到”: “1020”}, “7”:{ “从”: “540”, “为” : “1020”}}”
我想在Android Studio中对其进行解析,并仅出于这种结果进行迭代:
String day = monday;
int hourstart = from;
int hoursclose = to;
当然,从和到意味着数字。 有人知道JSON解析器的结构如何吗?
尝试这个:
//here jsonString is your json in string format
JSONObject obj3=new JSONObject(jsonString);
JSONObject obj4=null;
//Getting all the keys inside json object with keys- from and to
Iterator<String> keys= obj3.keys();
while (keys.hasNext())
{
String keyValue = (String)keys.next();
obj4 = obj3.getJSONObject(keyValue);
//getting string values with keys- from and to
String from = obj4.getString("from");
String to = obj4.getString("to");
int hourstart = Integer.parseInt(from);
int hoursclose = Integer.parseInt(to);
System.out.println("From : "+ hourstart +" To : "+ hoursclose);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.