【发布时间】:2011-05-31 11:36:39
【问题描述】:
首先感谢 Pentium10 提供this answer!它让我更进一步。
我有一个由 php 生成的 JSONArray
echo (json_encode($output));
产生这个输出
// linebreaks only for readability, they do not exist in the response
[["Fitch's Chemist","731 Hay St","(08) 9321 6411"],
["Ferrara Karaoke Bar","67 Milligan Street","(08) 9481 1909"],
["Target: Perth","712-720 Hay St","(08) 9327 3700"],
["C Restaurant","44 St Georges Tce","(08) 9220 8333"],
["Celona Joe Tailors","146 Murray St","(08) 9325 8274"],
["Fashion In Colour","Shop 2, 138 Barrack St","(08) 9218 8233"],
["Mainpeak","858 Hay St","(08) 9322 9044"],
["Fj Storen Painting Contractors","34 Queen St","(08) 9486 9292"],
["Financial Pathfinders","Level 4\/81 St Georges Tce","(08) 9213 9699"],
["Seasons of Perth","37 Pier St","(08) 9325 7655"],
["David Jones","622 Hay St","(08) 9210 4000"],
["Pharmacity Chemist Supermart","717 Hay St","(08) 9322 6921"],
["Austcare","10 Pier St","(08) 9325 9330"],
["Western Australia","8 Pier St","(08) 9261 6222"],
["Oceanic Cruises","5 Barrack","(08) 9325 1191"]]
这会输出如下填充的列表数组;
list(0)["Fitch's Chemist","731 Hay St","(08) 9321 6411"]
list(1)["Ferrara Karaoke Bar","67 Milligan Street","(08) 9481 1909"]
我现在需要做的是进一步提取它,以便将 "" 封闭的数据存储在三个单独的数组中
try {
JSONArray jsonArray = new JSONArray(response);
List<String> list = new ArrayList<String>();
for (int i=0; i<jsonArray.length(); i++) {
list.add( jsonArray.getString(i) );
JSONArray jsonList = new JSONArray(list);
BusinessName.add(jsonList.getString(0));
Address.add(jsonList.getString(1));
TelNo.add(jsonList.getString(2));
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
谢谢马丁
【问题讨论】:
-
你能显示打印列表(0)的代码吗...你粘贴的?
-
您添加到问题中的代码是否有效?你应该多交流一点:)
-
对不起,你是对的。请耐心等待这是我的第一篇文章。不,代码不起作用,它会抛出 JSON 错误 int 超出范围