2013-07-28 76 views
0

我打印對象body在控制檯看到它有物業「成果」,但是當我嘗試打印body.resultsundefined對象屬性未定義的,但我看它是不是

body.results 
undefined 

body是JSON對象from google geocoder:

body 
"{ 
    "results" : [ 
     { 
     "address_components" : [ 
      { 
       "long_name" : "ulitsa Solnechnaya", 
       "short_name" : "ul. Solnechnaya", 
       "types" : [ "route" ] 
      }, 
      { 
       "long_name" : "Langepas", 
       "short_name" : "Langepas", 
       "types" : [ "locality", "political" ] 
      }, 
      { 
       "long_name" : "gorod Langepas", 
       "short_name" : "g. Langepas", 
       "types" : [ "administrative_area_level_2", "political" ] 
      }, 
      { 
       "long_name" : "Khanty-Mansi Autonomous Okrug", 
       "short_name" : "Khanty-Mansi Autonomous Okrug", 
       "types" : [ "administrative_area_level_1", "political" ] 
      }, 
      { 
       "long_name" : "Russia", 
       "short_name" : "RU", 
       "types" : [ "country", "political" ] 
      } 
     ], 
     "formatted_address" : "ulitsa Solnechnaya, Langepas, Khanty-Mansi Autonomous Okrug, Russia", 
     "geometry" : { 
      "bounds" : { 
       "northeast" : { 
        "lat" : 61.2641430, 
        "lng" : 75.20092810 
       }, 
       "southwest" : { 
        "lat" : 61.24910500000001, 
        "lng" : 75.16912719999999 
       } 
      }, 
      "location" : { 
       "lat" : 61.256440, 
       "lng" : 75.18677180 
      }, 
      "location_type" : "GEOMETRIC_CENTER", 
      "viewport" : { 
       "northeast" : { 
        "lat" : 61.2641430, 
        "lng" : 75.20092810 
       }, 
       "southwest" : { 
        "lat" : 61.24910500000001, 
        "lng" : 75.16912719999999 
       } 
      } 
     }, 
     "partial_match" : true, 
     "types" : [ "route" ] 
     } 
    ], 
    "status" : "OK" 
} 

我想要:var loc = body.results[0].geometry.location

+1

嘗試做'typeof運算body'。你看到了什麼? – Cherniv

回答

1

JSON.parse是我需要

var loc = (JSON.parse(body)).results[0].geometry.location 
相關問題