我从服务器获取了一个JSONArray,它是我发送给服务器的电子邮件的报告。我的目标是通过它,选择一个具有特定主题的那个并打印"收到的"数组中该元素的数字。 JSON看起来像这样:
[
{"rejections":58,"timestamp":"2014-08-08 12:46:26","subject":"2014/08/08 12:46:03.604: apitest ACTION_100_","clicks":0,"opens":28,"streams":0,"received":86,"bounces":0,"complaints":0,"unsubs":0}
{"rejections":77,"timestamp":"2014-08-11 13:54:49","subject":"2014/08/11 13:54:25.786: apitest ACTION_100_","clicks":0,"opens":14,"streams":0,"received":91,"bounces":0,"complaints":0,"unsubs":0}
]
我基本上试图回应与主题为"recieved":
的{{1}}相关联的数字...我不知道如何执行if语句。我知道它看起来像是:
"2014/08/11 13:54:25.786: apitest ACTION_100_"
我的代码:
if(thisElement["subject"].equals("2014/08/11 13:54:25.786: apitest ACTION_100_")){
echo thisElement["recieved"];
}`
答案 0 :(得分:1)
http://www.json.org/javadoc/org/json/JSONObject.html
if (newSubj.equals(obj.get("subject")) {
int received = obj.getInt("received");
System.out.println(received);
}