繁体   English   中英

在Java Android中解析JSON代码

[英]parse JSON code in java Android

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

{
  "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");
 }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM