我有一个包含范信息的文件
喜欢这个
name: "test',
address:"test",
"area" : [
{
"end_point_click" : "(10.577011981272062, 76.03049470111728)",
"description_of_work" : "dfgfdgd",
"head_area" : "Thrissur",
"start_point_click" : "(10.525709313612015, 76.22000886127353)",
"route_name" : "Thrissur Guruvayoor",
"start_location" : "Thrissur",
"end_location" : "Guruvayoor",
"lead_info" : [
{
"latlng" : "(10.575054561328756,76.08472825493664)",
"unique_key" : "Ammu,Paru,fdh,43543534"
}
]
},
{
"end_point_click" : "(10.335815561982484, 76.22000886127353)",
"description_of_work" : "dgdf",
"head_area" : "Thrissur",
"start_point_click" : "(10.516663022805359, 76.21451569721103)",
"route_name" : "Thrissur Irinjalakuda",
"start_location" : "Thrissur",
"end_location" : "Irinjalakuda"
},
{
"end_point_click" : "(10.554061845632159, 76.3614578358829)",
"description_of_work" : "dfsfdfs",
"head_area" : "Thrissur",
"start_point_click" : "(10.516257889923311, 76.21726227924228)",
"route_name" : "Thrissur Pattikadu",
"start_location" : "Thrissur",
"end_location" : "Pattykadu"
}
]
我想在json中循环标记。
使用此代码检索它:
markret = list(collectionnew.find(
{ 'area':
{ '$elemMatch':
{ 'route_name': post_text }
}
},{ '_id':0 ,
'area' :
{
'$elemMatch':
{'route_name': post_text}
}}
));
您可以在上面的一个文档中注明包含区域+潜在客户信息
"lead_info" : [
{
"latlng" : "(10.575054561328756,76.08472825493664)",
"unique_key" : "Ammu,Paru,fdh,43543534"
}
]
其他文档在解析json响应时不包含
if (typeof (JSON.stringify(data[0][0].lead_info[0].latlng)) != 'undefined')
如果该字段不存在则产生错误,我该如何解决。