我遇到了JSON数组的问题。首先,我有一组从下面的API中检索的JSON数组
{
"image_path":[
"slider.jpg",
"slider_2.jpg",
"slider_3.jpg",
"slider_4.jpg"
],
"name":[
"KIDCARD Banner",
"Christmas",
"Back To School",
"Chinese New Year"
],
"start_time":[
"2015-11-24 01:12:04",
"2015-11-24 04:31:26",
"2015-11-24 01:11:30",
"2015-11-29 01:11:07"
],
"end_time":[
"2020-12-31 01:12:04",
"2016-01-31 04:31:26",
"2016-01-20 01:11:30",
"2016-02-22 01:11:07"
]
}
但是,我只想在" name"中获取数据。并根据它显示。我可以用var array = title.split("","")分割它;在javascript中,但显示的结果是"圣诞节"我只想要圣诞节。所以我需要帮助来删除""在这个词上。我是javascript来做的。谢谢。
答案 0 :(得分:3)
你可以得到这样的名字
var arr={
"image_path":[
"slider.jpg",
"slider_2.jpg",
"slider_3.jpg",
"slider_4.jpg"
],
"name":[
"KIDCARD Banner",
"Christmas",
"Back To School",
"Chinese New Year"
],
"start_time":[
"2015-11-24 01:12:04",
"2015-11-24 04:31:26",
"2015-11-24 01:11:30",
"2015-11-29 01:11:07"
],
"end_time":[
"2020-12-31 01:12:04",
"2016-01-31 04:31:26",
"2016-01-20 01:11:30",
"2016-02-22 01:11:07"
]
};
arr.name.forEach(function(i,j){
console.log(i)
});
答案 1 :(得分:0)
你的问题有点令人困惑。您是否已经解析了JSON数据,或者您是否将其视为字符串?如果是后者,则应使用JSON.parse
解析它。
假设您在data
中获得了一组数组,它看起来像是:
var arrays = JSON.parse(data);
var christmas = arrays.name[1];
然后christmas
将具有值#34;圣诞节"。或者您可以使用Array.forEach
或仅使用标准for
循环迭代数组。