【发布时间】:2015-06-25 11:37:25
【问题描述】:
我从 api 中提取 JSON 如下所示
{
"totalResults":1,
"items":[
{
"body":"here is the body",
"excerpt":"here is the exceprt",
"title":"article title",
"customFields":[
{
"basename":"image_title",
"value":""
},
{
"basename":"image_tag",
"value":""
},
{
"basename":"image_text",
"value":""
},
{
"basename":"image_01",
value: "<form mt:asset-id="428270" class="enclosure enclosure-image" style="display: inline;"><a href="http://mywebsite.com/news/images/2015/06/image.jpg">image.jpg</a></form>"
},
{
"basename":"image_01_cap",
"value":"some text for the captions"
}
]
}
]
}
我是新来的小胡子。我要解析的数据不是对象数组,而是具有数组值的对象。
到目前为止,我得到了这个,但没有任何输出。我还想从值中提取 img url。我正在使用最新版本的 Mustache.js 2.1.2
{{#items}}
{{#customFields}}
{{#basename.image_01}}
<img src="{{value}}">
{{/basename.image_01}}
{{/customFields}}
{{/items}}
我希望输出为:<img src="http://mywebsite.com/news/images/2015/06/image.jpg">
【问题讨论】:
-
你不是忽略项目吗?比如{{#items}}{{/items}}
-
@Skarlinski 谢谢该项目在我的原始代码中,但我有些遗漏了它。
标签: javascript json parsing templates mustache