0

我正在尝试解析 json 结果对象并在小部件中使用 html 模板来显示。

json看起来像这样

 Result": [
{
    "Website": "Testing ",
    "Description": "Content from yahoo ",


    "LinkGroup": {
        "entry": [
            {
                "linkType": "information",
                "Link": {
                    "title": "Test1",
                    "url": "http://yahoo.com",
                    "description": "my Link Description"
                }
            },
            {
                "linkType": "news link",
                "Link": {
                    "title": "Test 2",
                    "url": "http://www.yahoo.com/news link...",
                    "description": "news link Link Description"
                }
            }
        ]
    }
}, 
{
    "Website": "Testing 2",
    "Description": "Content from google ",


    "LinkGroup": {
        "entry": [
            {
                "linkType": "information",
                "Link": {
                    "title": "Test1",
                    "url": "http://google.com",
                    "description": "my Link Description"
                }
            },
            {
                "linkType": "news link",
                "Link": {
                    "title": "Test 2",
                    "url": "http://www.google.com/news link...",
                    "description": "news link Link Description"
                }
            }
        ]
    }
},

我之前能够仅解析条目项并将其用于模板化小部件。我现在想在我的小部件中使用网站和描述对象。我尝试解析 Result 对象并尝试访问条目,而不是条目数组对象。查看控制台日志,我看到它在尝试获取条目值时停止。我想知道如何解析它,以便我可以首先获取网站和描述,然后在其中添加条目。这是我的 html 小部件代码

                 <div><span title="${Link.description}">${Link.description</span>/div> <br />
              <a href="${Link.url}">${Link.title}</a><br />

我用这段代码解析 json

                 request("js/my/data/sample.json", {
                handleAs: "json"}).then(function(jsonResults){ 
                arrayUtil.forEach(jsonResults.LinksGroup, function(List) 
              {arrayUtil.forEach(List.LinksGroup.entry, function(Ientry){
               var widget = new support(Ientry).placeAt(authorContainer);

               });});
4

1 回答 1

0

我找到了答案。我在输入对象之前使用了数组中的另一个小部件来解决问题。

于 2013-05-01T04:00:09.533 回答