2017-06-25 10 views
-2

下のオブジェクトを解析する方法の例をいくつか教えてもらえますか? 私が必要とするのは、1つのフィールドです。angular2のJSONデータを解析して表示する

私は複雑なものではなく、単純なオブジェクトで多くの例を見ています。

{ "結果":[{ "address_components":[{ "LONG_NAME": "ナッシュビル"、 "SHORT_NAME": "ナッシュビル"、 "タイプ": "地域"、 "政治"]}、 {"long_name": "テネシー州"、 "short_name": "TN"} {"long_name": "Davidson County"、 "short_name": "Davidson County"、 "types":["administrative_area_level_2"、 "political" ["long_name": "アメリカ合衆国"、 "short_name": "US"、 "types":["country"、 "political"]}]、 "north":{"lat":36.4054959、 "lng": - 86.5155879}、 "southwest":{"lat": ""} "formatted_address": "テネシー州ナッシュビル" 35.9677851、 "lng": - 87.054903}}、 "location":{"lat":36.1626638、 "lng": - 86.7816016}、 "location_type": "APPROXIMATE"、 "viewport":{"northeast":{"lat ":36.4054959、" lng ": - 86.5155879}、"南西 ":{" lat ":35.9677851、" lng ": - 87.054903}}}" place_id ":" ChIJPZDrEzLsZIgRoNrpodC5P30 "、" types ":[" locality " 、 "political"]}]、 "status": "OK"}

+0

これは「解析中」ではありませんが、これは異なるものです。その言葉を使わないでください。それは「アクセスしている」。 Angularとは何の関係もありません。それは普通の古いJavaScriptです。あなたのタイトルは「解析して表示する」と言っています。あなたの質問には "解析"が記載されていますが、 "表示"されません。あなたの問題は、それを "解析"するか、それを "表示"したいのですか?あなたはどちらのフィールドをお探しですか?どのような問題にアクセスしていますか? –

+2

[アクセス/プロセス(入れ子にされた)オブジェクト、配列、またはJSON]の重複の可能性があります(https://stackoverflow.com/questions/11922383/access-process-nested-objects-arrays-or-json) –

答えて

0

どのフィールドを使いたいですか?あなたのオブジェクトはすでにOKだと思われるからです。 例で:

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}をしたい場合は、あなたが使用することができます。

var southwestValues = test.results[0].geometry.bounds.southwest; 
var lat = southwestValues.lat; // gives you 35.9677851 
var long = southwestValues.lng; // gives you -87.054903 

答えは、あなたが探していたということですか?

+0

これは質問に答えてください。批評をしたり、著者の説明を求めるには、投稿の下にコメントを残してください。 - [レビューから](評価版/レビュー/低品質の投稿/ 16521195) – David

+0

南西の緯度と経度は「 –

+0

南西」:{"lat":35.9677851、 "lng": - 87.054903} –

関連する問題