0

我有一个从 web 服务返回的以下 JSON。但我只需要在我的Sencha 触摸网格中显示三个字段。有没有办法得到它

我的杰森

    {
  "@timestamp": "2013-6-27_183319",
  "@protocol": "SAML2.0",
  "@title": "Some radom Message ",
  "#text": "Some radom Message",
  "description": "Some radom Message",
  "chart": "ReportGeneration_default.jpg",
  "validations":   [
        {
      "@filename": "authnrequest1_2013-6-27_183319.xml",
      "links": {"messagelink": "},
      "protocol":       {
        "version": "2.0",
        "inference": "passed"
      },
      "validationtype":       {
        "@method": "deployment specific validation",
        "category":         {
          "@name": "Authentication Request",
          "rules":           [
                        {
              "@name": "Destination",
              "inference": "passed",
              "messagevalid": "Some radom Message"
            },
                        {
              "@name": "ID",
              "inference": "passed",
              "messagevalid": "_cc9a8360-c156-0130-2d3f-00304834ee22"
            },
                        {
              "@name": "Version",
              "inference": "passed",
              "messagevalid": "2.0"
            },
                        {
              "@name": "IssueInstant",
              "inference": "passed",
              "messagevalid": "2013-06-27T12:55:42Z"
            },
                        {
              "@name": "Issuer",
              "inference": "passed",
              "messagevalid": "Some radom Message"
            },
                        {
              "@name": "Issuer Format",
              "inference": "passed",
              "messagevalid": "Some radom Message"
            },
                        {
              "@name": "AllowCreate",
              "inference": "passed",
              "messagevalid": "true"
            },
                        {
              "@name": "NameIDPolicy Format",
              "inference": "passed",
              "messagevalid": "Some radom Message"
            }
          ],
          "summary":           {
            "validationpassed": "8",
            "validationfailed": "0",
            "passpercentage": "100"
          }
        }
      }
    },
        {
      "@filename": "assertion2_2013-6-27_183319.xml",
      "links": {"messagelink": ""},
      "protocol":       {
        "version": "2.0",
        "inference": "passed"
      },
      "validationtype":       {
        "@method": "deployment specific validation",
        "category":         {
          "@name": "Response",
          "rules":           [
                        {
              "@name": "Response is signed (Optional)",
              "inference": "passed",
              "messagevalid": "false"
            },
                        {
              "@name": "Assertion is signed",
              "inference": "passed",
              "messagevalid": "true"
            },
                        {
              "@name": "Assertion is encrypted",
              "inference": "passed",
              "messagevalid": "true"
            },
                        {
              "@name": "Signing Certificate is valid",
              "inference": "passed",
              "messagevalid": "Some radom Message"
            },
                        {
              "@name": "Version is present",
              "inference": "passed",
              "messagevalid": "2.0"
            },
                        {
              "@name": "Destination is present",
              "inference": "passed",
              "messagevalid": "Some radom Message"
            },
                        {
              "@name": "IssueInstant is present",
              "inference": "passed",
              "messagevalid": "2013-06-27T12:52:54Z"
            },
                        {
              "@name": "Issuer is present",
              "inference": "passed",
              "messagevalid": "true"
            },
                        {
              "@name": "Issuer is a URL reference to the partner entity-ID",
              "inference": "passed",
              "messagevalid": "urn:oasis:names:tc:SAML:2.0:nameid-format:entity"
            },
                        {
              "@name": "Number of Subject elements is 1",
              "inference": "passed",
              "messagevalid": "true"
            },
                        {
              "@name": "SubjectConfirmation element contains confirmation Method of urn:oasis:names:tc:SAML:2.0:cm:bearer",
              "inference": "passed",
              "messagevalid": "urn:oasis:names:tc:SAML:2.0:cm:bearer"
            },
                        {
              "@name": "NameID is present",
              "inference": "passed",
              "messagevalid": "Some radom Message"
            },
                        {
              "@name": "NameID format attribute Value is urn:oasis:names:tc:SAML:2.0:nameid-format:persistent or urn:oasis:names:tc:SAML:2.0:nameid-format:unspecified",
              "inference": "passed",
              "messagevalid": "Some radom Message"
            },
                        {
              "@name": "SubjectConfirmationData includes InResponseTo",
              "inference": "passed",
              "messagevalid": "_cc9a8360-c156-0130-2d3f-00304834ee22"
            },
                        {
              "@name": "SubjectConfirmationData includes NotOnOrAfter",
              "inference": "passed",
              "messagevalid": "2013-06-27T21:13:54Z"
            },
                        {
              "@name": "SubjectConfirmationData includes Recipient",
              "inference": "passed",
              "messagevalid": "Some radom Message"
            },
                        {
              "@name": "Conditions NotBefore is present",
              "inference": "passed",
              "messagevalid": "2013-06-27T04:32:54Z"
            },
                        {
              "@name": "Conditions NotOnOrAfter is present",
              "inference": "passed",
              "messagevalid": "2013-06-27T21:13:54Z"
            },
                        {
              "@name": "AudienceRestriction is present",
              "inference": "passed",
              "messagevalid": "true"
            },
                        {
              "@name": "Audience is present",
              "inference": "passed",
              "messagevalid": "Some radom Message"
            },
                        {
              "@name": "Number of AuthnStatement elements is 1",
              "inference": "passed",
              "messagevalid": "true"
            },
                        {
              "@name": "AuthnStatement includes AuthnInstant",
              "inference": "passed",
              "messagevalid": "2013-06-27T12:52:53Z"
            },
                        {
              "@name": "AuthnStatement includes SessionIndex",
              "inference": "passed",
              "messagevalid": "N3zGHc711KOX0gfhH6Ce/4MrLV8=jY/Ixg=="
            },
                        {
              "@name": "AuthnStatement includes SessionNotOnOrAfter",
              "inference": "passed",
              "messagevalid": "2013-06-27T21:13:54Z"
            },
                        {
              "@name": "Number of AttributeStatement elements is 1",
              "inference": "passed",
              "messagevalid": "true"
            },
                        {
              "@name": "ID is present",
              "inference": "passed",
              "messagevalid": "_a86b41c1d7153b8d71b722a81b559b55df6d"
            },
                        {
              "@name": "InResponseTo",
              "inference": "passed",
              "messagevalid": "_cc9a8360-c156-0130-2d3f-00304834ee22"
            },
                        {
              "@name": "AuthnContextClassRef is present",
              "inference": "passed",
              "messagevalid": "urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport"
            },
                        {
              "@name": "AttrName",
              "inference": "passed",
              "messagevalid": "email"
            },
                        {
              "@name": "AttrValue",
              "inference": "passed",
              "messagevalid": "Some radom Message"
            },
                        {
              "@name": "NameFormat",
              "inference": "passed",
              "messagevalid": "urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified"
            },
                        {
              "@name": "AttrName",
              "inference": "passed",
              "messagevalid": "guid"
            },
                        {
              "@name": "AttrValue",
              "inference": "passed",
              "messagevalid": "4658701f7440dc53e3d2a0ef36b0cf96"
            },
                        {
              "@name": "NameFormat",
              "inference": "passed",
              "messagevalid": "urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified"
            },
                        {
              "@name": "AttrName",
              "inference": "passed",
              "messagevalid": "display_name"
            },
                        {
              "@name": "AttrValue",
              "inference": "passed",
              "messagevalid": "Some radom Message"
            },
                        {
              "@name": "NameFormat",
              "inference": "passed",
              "messagevalid": "urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified"
            }
          ],
          "summary":           {
            "validationpassed": "36",
            "validationfailed": "0",
            "passpercentage": "100"
          }
        }
      }
    }
  ]
}

我试过商店映射

在 JSON 值中,我需要显示 @name、interference 和 message 字段。我尝试了映射功能,但效果很好,还有其他想法吗?

4

2 回答 2

1

这有帮助吗?如果您不使用 JSONReader,则映射属性似乎存在问题。

http://www.sencha.com/forum/showthread.php?130134-CLOSED-Field-mapping-property-ignored-when-creating-Model-instance

于 2013-08-21T19:52:52.703 回答
1

您可以为 store::setData 方法编写自己的映射到这样的东西

Ext.define('App.store.DemoStore', {
extend: 'Ext.data.Store',

config: {
    model: 'App.model.DemoModel',
    storeId: 'Demo',
    autoLoad: true,
    autoSync: true,
    proxy: {
        type: 'localstorage',
        id: 'demo-data'
    }
},

setData: function (data) {
    var mappingObj = {},
        newData = [];

    // get mappings from model
    Ext.each(this.getModel().getFields().all, function (singleField) {
        // name and mapping of the field
        var name =      singleField._name,
            mapping =   singleField._mapping;

        if (mapping){
            mappingObj[name] = mapping;
        }
    });

    Ext.each(data, function (singleData) {
        // main mapping
        Ext.Object.each(mappingObj, function(item){
            singleData[item] = singleData[mappingObj[item]];
            delete singleData[mappingObj[item]];
        });

        newData.push(singleData);
    });

    // start the original setData(data)
    this.callParent(newData);
}

});

于 2016-03-05T15:44:20.657 回答