解析此JSON [英] parsing this JSON
本文介绍了解析此JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图分析此JSONbut它没有关于该数组我会得到计数。
I am trying to parse this JSONbut it does not have the array with respect i will get the count.
当我用来解析
如果JSONwill是:
As I used to parse if the JSONwill be:
{
"earthquakes": [
{
"eqid": "c0001xgp",
"magnitude": 8.8,
"lng": 142.369,
"src": "us",
"datetime": "2011-03-11 04:46:23",
"depth": 24.4,
"lat": 38.322
},
{
"eqid": "2007hear",
"magnitude": 8.4,
"lng": 101.3815,
"src": "us",
"datetime": "2007-09-12 09:10:26",
"depth": 30,
"lat": -4.5172
},
{
"eqid": "2007aqbk",
"magnitude": 8,
"lng": 156.9567,
"src": "us",
"datetime": "2007-04-01 18:39:56",
"depth": 10,
"lat": -8.4528
},
{
"eqid": "2007hec6",
"magnitude": 7.8,
"lng": 100.9638,
"src": "us",
"datetime": "2007-09-12 21:49:01",
"depth": 10,
"lat": -2.5265
},
{
"eqid": "a00043nx",
"magnitude": 7.7,
"lng": 100.1139,
"src": "us",
"datetime": "2010-10-25 12:42:22",
"depth": 20.6,
"lat": -3.4841
},
{
"eqid": "2010utc5",
"magnitude": 7.7,
"lng": 97.1315,
"src": "us",
"datetime": "2010-04-06 20:15:02",
"depth": 31,
"lat": 2.3602
},
{
"eqid": "2009mebz",
"magnitude": 7.6,
"lng": 99.9606,
"src": "us",
"datetime": "2009-09-30 08:16:09",
"depth": 80,
"lat": -0.7889
},
{
"eqid": "2009kdb2",
"magnitude": 7.6,
"lng": 92.9226,
"src": "us",
"datetime": "2009-08-10 17:55:39",
"depth": 33.1,
"lat": 14.0129
},
{
"eqid": "2010zbca",
"magnitude": 7.6,
"lng": 123.533,
"src": "us",
"datetime": "2010-07-23 20:51:11",
"depth": 576.3,
"lat": 6.4939
},
{
"eqid": "2010xkbv",
"magnitude": 7.5,
"lng": 91.9379,
"src": "us",
"datetime": "2010-06-12 17:26:50",
"depth": 35,
"lat": 7.7477
}
]
}
在code:
JSONObject json = JSONfunctions.getJSONfromURL("url");
JSONArray earthquake= json.getJSONArray("earthquakes");
但我有这种类型的
but i have got this type
[
{
"id": "4",
"head": "gggg",
"details": "gdhghfhgfh",
"d2": "jkjkjk",
"datetime": "2012-03-12",
"last_update": "2012-03-14 05:08:32"
},
{
"id": "5",
"head": "bb1",
"details": "sddassa",
"d2": "ddsdsddsd",
"datetime": "0000-00-00",
"last_update": "2012-03-13 07:33:56"
},
{
"id": "3",
"head": "hhh",
"details": "hhhh",
"d2": "dsdsdds",
"datetime": "2012-03-01",
"last_update": "2012-03-12 08:35:27"
}
]
有没有像在previous一大地震。
there is nothing like "earthquake" in previous one.
推荐答案
您可以直接转换成服务器的响应数据的数组,那么你可以将其直接使用转换成JSONArray JSONArray ARR =新JSONArray( stringResponse);
You can directly convert server response is an array of data, then you can directly convert it into JSONArray using JSONArray arr = new JSONArray(stringResponse);
如果你在JSON字符串的响应,那么你可以把它转换成JSONArray如下:
If you get JSON response in string then you can convert it into JSONArray as follows
String stringResponse = JSONfunctions.getJSONResponsefromURL("url");
try {
JSONArray arr = new JSONArray(stringResponse);
} catch (JSONException e) {
e.printStackTrace();
}
这篇关于解析此JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文