尝试使用逗号过滤位置数据时,但出现错误 [object Object],[object Object],[object Object Object],[object Object] 数据json:
{
"command": "lok",
"params": {
"action": "test",
},
"response": {
"skc": "D400",
"location": [
{
"city": "Lond.",
"location": "1m23"
},
{
"city": "Lond.",
"location": "2df65"
},
{
"city": "Lond.",
"location": "3sk56"
}
]
}
}
js代码如下所示:
var lk = data.response.location;
console.log(lk);
var ghlok = lk.filter(function (item) {
return item.location;
}).join(",");
console.log(ghlok);
console.log(lk);
给出位置 {"city": "Lond.", "location": "1m23"}...
console.log(ghlok);
输出 [object Object Object],[object Object],...
我添加了
var par = JSON.parse(lk);
但我收到错误
意外的标记“o”,“[object Object Object”...不是有效的 JSON
var lk = data.response.location;
console.log(lk);
var ghlok = lk.map(function (item) {
return item.location;
}).join(",");
console.log(ghlok);