在angular2中解析并显示JSON数据

时间:2017-06-25 01:17:56

标签: javascript

有人可以举一些例子来解析下面的对象吗? 我只需要一个领域。

我看到很多关于简单对象的例子,而不是复杂的。

  

{ “结果”:[{ “address_components”:[{ “LONG_NAME”: “纳什维尔”, “SHORT_NAME”: “纳什维尔”, “类型”:[ “局部性”, “政治”]},{“LONG_NAME “:”Davidson County“,”short_name“:”Davidson County“,”types“:[”administrative_area_level_2“,”political“]},{”long_name“:”Tennessee“,”short_name“:”TN“,”types“ “:[”administrative_area_level_1“,”political“]},{”long_name“:”美国“,”short_name“:”美国“,”类型“:[”country“,”political“]}],”formatted_address“ :“Nashville,TN,USA”,“geometry”:{“bounds”:{“northeast”:{“lat”:36.4054959,“lng”: - 86.5155879},“southwest”:{“lat”:35.9677851,“ LNG “: - 87.054903}},” 位置 “:{” LAT “:36.1626638,” 液化天然气 “: - 86.7816016},” LOCATION_TYPE “:” 近似”, “视”:{ “东北”:{ “LAT”:36.4054959 “液化天然气”: - 86.5155879}, “西南”:{ “LAT”:35.9677851, “液化天然气”: - 87.054903}}}, “place_id”: “ChIJPZDrEzLsZIgRoNrpodC5P30”, “类型”: “本地”, “政治” ]}], “状态”: “OK”}

1 个答案:

答案 0 :(得分:0)

你想要哪个领域?因为你的对象似乎已经可以了。 例如:

@app.route('/post/', methods=['POST'])
def post():
    if request.is_json:
        data = request.get_json()
        return jsonify(data)
    else:
        return jsonify(status="Request was not JSON")

如果您需要var test = {"results":[{"address_components":[{"long_name":"Nashville","short_name":"Nashville","types":["locality","political"]},{"long_name":"Davidson County","short_name":"Davidson County","types":["administrative_area_level_2","political"]},{"long_name":"Tennessee","short_name":"TN","types":["administrative_area_level_1","political"]},{"long_name":"United States","short_name":"US","types":["country","political"]}],"formatted_address":"Nashville, TN, USA","geometry":{"bounds":{"northeast":{"lat":36.4054959,"lng":-86.5155879},"southwest":{"lat":35.9677851,"lng":-87.054903}},"location":{"lat":36.1626638,"lng":-86.7816016},"location_type":"APPROXIMATE","viewport":{"northeast":{"lat":36.4054959,"lng":-86.5155879},"southwest":{"lat":35.9677851,"lng":-87.054903}}},"place_id":"ChIJPZDrEzLsZIgRoNrpodC5P30","types":["locality","political"]}],"status":"OK"}; test.results[0].place_id; // will give you "ChIJPZDrEzLsZIgRoNrpodC5P30" ,可以使用:

"southwest":{"lat":35.9677851,"lng":-87.054903}

这是你要找的答案吗?