• json对象的解析


    json对象数据:

    {
      "status": "200",
      "code": "",
      "msg": "",
      "data": {
        "departId": 68120,
        "departName": "业务部",
        "orderNo": 2,
        "status": 1,
        "departLevel": 1,
        "departParent": 0,
        "departPath": "/0",
        "createTime": 1457094375000,
        "updateTime": 1480065850000,
        "companyId": 2446,
        "phoneCount": 0,
        "childDeparts": [],
        "parentDeparts": [
          {
            "departId": 68120,
            "departName": "业务部",
            "orderNo": 2,
            "status": 1,
            "departLevel": 1,
            "departParent": 0,
            "departPath": "/0",
            "createTime": 1457094375000,
            "updateTime": 1480065850000,
            "companyId": 2446,
            "phoneCount": 0,
            "childDeparts": [],
            "parentDeparts": [],
            "departPhones": []
          }
        ],
        "departPhones": [
          {
            "id": 1352908,
            "companyId": 2446,
            "fixPhone": "13952089911",
            "orderNo": 0,
            "phoneName": "高峥",
            "pinyin": "gaozhengrong ",
            "departId": 68120,
            "departName": "",
            "status": 1,
            "expand": ""
          },
          {
            "id": 1203270,
            "companyId": 2446,
            "fixPhone": "18602956699",
            "orderNo": 0,
            "phoneName": "华明",
            "pinyin": "weihuaming?",
            "departId": 68120,
            "departName": "",
            "status": 1,
            "expand": "18767173160,18767173161,18767173162"
          },
          {
            "id": 1203271,
            "companyId": 2446,
            "fixPhone": "13993000256",
            "orderNo": 0,
            "phoneName": "胡文杰",
            "pinyin": "xuwenjie?",
            "departId": 68120,
            "departName": "",
            "status": 1,
            "expand": ""
          },
          {
            "id": 1204775,
            "companyId": 2446,
            "fixPhone": "18668407878",
            "orderNo": -1,
            "phoneName": "徐永",
            "pinyin": "xuyongjie?",
            "departId": 68120,
            "departName": "",
            "status": 1,
            "expand": ""
          },
          {
            "id": 1206865,
            "companyId": 2446,
            "fixPhone": "13893600043",
            "orderNo": 0,
            "phoneName": "白菜",
            "pinyin": "nihai?",
            "departId": 68120,
            "departName": "",
            "status": 1,
            "expand": ""
          },
          {
            "id": 1250141,
            "companyId": 2446,
            "fixPhone": "13385817511",
            "orderNo": 5,
            "phoneName": "baobao1",
            "pinyin": "baobao1?",
            "departId": 68120,
            "departName": "",
            "status": 1,
            "expand": ""
          },
          {
            "id": 1250146,
            "companyId": 2446,
            "fixPhone": "13385817513",
            "orderNo": 6,
            "phoneName": "baobao3",
            "pinyin": "baobao3?",
            "departId": 68120,
            "departName": "",
            "status": 1,
            "expand": ""
          },
          {
            "id": 1352823,
            "companyId": 2446,
            "fixPhone": "13758230573",
            "orderNo": 0,
            "phoneName": "萝卜",
            "pinyin": "chen shen ",
            "departId": 68120,
            "departName": "",
            "status": 1,
            "expand": "12345678977"
          }
        ]
      }
    }

    注意这个json对象下的expand下会存在多个号码,现在遇到的问题时,这8个对象的数组能够分别渲染到结构中,问题时expand下的多个号码,怎样依次渲染出来,问题还在解决中:

    $.each(data.data.departPhones,function (i,item) {
        console.log(item)
    })

    通过$.each,可以得到:

    考虑到是json数据的分割处理:

    搜到了类似的情况:http://cnodejs.org/topic/5354bd3b1969a7b22af6ab0f

    可能暂时用这种方法试试看。

    麻烦大家看看,有没有什么好的解决方案。

    补充:

    http://caibaojian.com/json-length.html

    JSON数组有长度json.abc.length,如果单纯是json格式,那么不能直接使用json.length方式获取长度,而应该使用其他方法。

  • 相关阅读:
    C++访问WebService gSoap方式
    vc6
    POS 60域用法
    本次操作由于这台计算机的限制而被取消
    POS的一点杂笔
    QT5.5
    注册表常用快捷键
    WebBrowser与IE的关系,如何设置WebBrowser工作在IE9模式下?
    js中的prototype属性
    WPF入门教程系列二十——ListView示例(二)
  • 原文地址:https://www.cnblogs.com/wang715100018066/p/6144918.html
Copyright © 2020-2023  润新知