gpt4 book ai didi

java - 在java Android中解析JSON代码

转载 作者:行者123 更新时间:2023-12-01 12:59:50 25 4
gpt4 key购买 nike

我正在尝试解析此代码:我需要“响应”下“文档”下的“名称”属性。

{
"responseHeader": {
"status": 0,
"QTime": 1,
"params": {
"q": "Lecture1-2",
"_": "1399736575991",
"wt": "json"
}
},
"response": {
"numFound": 6,
"start": 0,
"docs": [
{
"id": "TWINX2048-3200PRO",
"name": "CORSAIR XMS 2GB (2 x 1GB) 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) Dual Channel Kit System Memory - Retail",
"manu": "Corsair Microsystems Inc.",
"manu_id_s": "corsair",
"cat": [
"electronics",
"memory"
],
"features": [
"CAS latency 2,\t2-3-3-6 timing, 2.75v, unbuffered, heat-spreader"
]}}

我尝试这样做:

JSONObject nodeRoot  = new JSONObject(result); 
JSONObject nodeStats = nodeRoot.getJSONObject("response");
String sSDR = nodeStats.getString("docs");

但我有其他结果...

最佳答案

"docs": [ 是一个 JSONArray

你拥有什么

 String sSDR = nodeStats.getString("docs");

更改为

 JSONObject nodeStats = nodeRoot.getJSONObject("response");
JSONArray jr = (JSONArray) nodeStats.getJSONArray("docs");
for(int i=0;i<jr.length();i++)
{
JSONObject jb = jr.getJSONObject(i);
String id = jb.getString("id");
}

关于java - 在java Android中解析JSON代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23592614/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com