【问题标题】:parse JSON code in java Android在 java Android 中解析 JSON 代码
【发布时间】:2014-05-11 12:26:58
【问题描述】:

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

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

但我还有其他结果...

【问题讨论】:

    标签: java android json solr


    【解决方案1】:

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

    【讨论】:

    • 感谢它有效 :) 我很困惑如何区分数组和对象
    • @MedAmini [ 代表 JSONArray 节点,{ 代表 JSONObject 节点
    猜你喜欢
    • 2015-01-15
    • 1970-01-01
    • 2016-09-10
    • 1970-01-01
    • 2021-11-07
    • 2011-08-18
    • 1970-01-01
    • 2011-07-26
    • 1970-01-01
    相关资源
    最近更新 更多