如何获取指定的对象数据

时间:2017-10-20 16:14:59

标签: javascript jquery

基于从此JSON数据生成的对象,如何使用javascript或jQuery仅获取z:row个对象值?换句话说,如何从JSON过滤对象值?

{
  "Response": {
    "Request": {
      "ConnectInfo": {
        "USER_NAME": "",
        "PASSWORD": "",
        "PROJECT_ID": "",
        "CONNECTION_NAME": "",
        "APP_ID": "",
        "CLIENT_IP": "",
        "SITE": "",
        "LANGUAGE": "",
        "LANGUAGE_ID": "0"
      },
      "Method": {
        "MethodID": "",
        "Name": "",
        "PARAMS": {
          "PARAM": [{
              "@id": "",
              "@value": ""
            },
            {
              "@id": "",
              "@value": ""
            },
            {
              "@id": "",
              "@value": ""
            },
            {
              "@id": "",
              "@value": ""
            }
          ]
        },
        "QueryControl": {
          "chunk_num": "",
          "rev_control": "",
          "max_rows": ""
        }
      }
    },
    "MethodResponse": {
      "Name": "",
      "MethodID": "",
      "DeResult": {
        "xml": {
          "@xmlns:dt": "uuid:C2F41010-65B3-11d1-A29F-00AA00C14882",
          "s:Schema": {
            "@id": "RowsetSchema",
            "s:ElementType": {
              "@content": "eltOnly",
              "@name": "row",
              "s:AttributeType": [{
                  "@name": "BACKGROUND",
                  "@rs:maydefer": "true",
                  "@rs:nullable": "true",
                  "@rs:number": "1",
                  "@rs:writeunknown": "true",
                  "s:datatype": {
                    "@dt:maxLength": "2147483647",
                    "@dt:type": "string",
                    "@rs:precision": "0"

                  }
                ],
                "s:extends": {
                  "@types": "rs:rowbase"

                },
                "rs:data": {
                  "z:row": [{
                      "@BACKGROUND": "",
                      "@DOC.APP_FORMAT_TYPE": "NO VALUE",
                      "@DOC.AUTHOR": "",
                      "@DOC.Access_UDF": "Public",
                      "@DOC.BOM_DEFINING": "Yes",
                      "@DOC.CAGE_CODE": "CAGE_CODE1",
                    },
                    {
                      "@BACKGROUND": "",
                      "@DOC.APP_FORMAT_TYPE": "NO VALUE",
                      "@DOC.AUTHOR": "",
                      "@DOC.Access_UDF": "Public",
                      "@DOC.BOM_DEFINING": "Yes",
                      "@DOC.CAGE_CODE": "CAGE_CODE1",
                    },
                  ]
                },
                "ResultCode": "Ok",
                "ExtraResults": "",
                "Messages": "",
                "Trace": ""
              },
              "ResultCode": "Ok",
              "ExtraResults": "",
              "Messages": ""
            }
          }
          "

          <!-- begin snippet: js hide: false console: true babel: false -->

          <!-- language: lang-html -->

          "{
          "Response": {
            "Request": {
              "ConnectInfo": {
                "LANGUAGE_ID": "0"
              },
              "Method": {
                "MethodID": "",
                "Name": "",
                "PARAMS": {
                  "PARAM": [{
                    "@id": "",
                    "@value": ""
                  }]
                },
                "QueryControl": {
                  "chunk_num": "",
                }
              }
            },
            "MethodResponse": {
              "Name": "",
              "MethodID": "",
              "DeResult": {
                "xml": {
                  "@xmlns:dt": "uuid:C2F41010-65B3-11d1-A29F-00AA00C14882",
                  "s:Schema": {
                    "@id": "RowsetSchema",
                    "s:ElementType": {
                      "@content": "eltOnly",
                      "@name": "row",
                      "s:AttributeType": [{
                          "@name": "BACKGROUND",
                          "@rs:maydefer": "true",
                          "@rs:nullable": "true",
                          "@rs:number": "1",
                          "@rs:writeunknown": "true",
                          "s:datatype": {
                            "@dt:maxLength": "2147483647",
                            "@dt:type": "string",
                            "@rs:precision": "0"

                          }
                        ],
                        "s:extends": {
                          "@types": "rs:rowbase"

                        },
                        "rs:data": {
                          "z:row": [{
                              "@BACKGROUND": "",
                              "@DOC.APP_FORMAT_TYPE": "NO VALUE",
                              "@DOC.AUTHOR": "",
                              "@DOC.Access_UDF": "Public",
                              "@DOC.BOM_DEFINING": "Yes",
                              "@DOC.CAGE_CODE": "CAGE_CODE1",
                            },
                            {
                              "@BACKGROUND": "",
                              "@DOC.APP_FORMAT_TYPE": "NO VALUE",
                              "@DOC.AUTHOR": "",
                              "@DOC.Access_UDF": "Public",
                              "@DOC.BOM_DEFINING": "Yes",
                              "@DOC.CAGE_CODE": "CAGE_CODE1",
                            },
                          ]
                        },
                        "ResultCode": "Ok",
                        "ExtraResults": "",
                        "Messages": ""
                      }
                    }

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

我发现答案如下,我们可以通过每个对象。

     var obj = data;
                var json = JSON.parse(data)
               json.Response.MethodResponse.DeResult.xml["rs:data"]