객체에 요소를 식별해야한다고 생각하면 원하는 값을 얻을 수없는 시나리오가 발생합니다.JSONP 형식의 데이터 객체에서 값 검색
이 부분의 작품과 반환 된 데이터가 정확한지 : 내가지도를 가지고 있고지도에 건물을 식별 할 때, 나는 다음과 같은 JSON 객체를받을 (이 읽기 쉽도록하지만, 실제 생활에서 단축 된 , 적절히 형식화 됨) :지도를 클릭하면 MapClick (queryResults) 함수가 호출됩니다.
dojo.io.script.jsonp_dojoIoScript19._jsonpCallback({
"results": [
{
"layerId": 5,
"layerName": "Building",
"value": "Name of item clicked",
"displayFieldName": "name",
"attributes": {
"ID": "123",
"name": "Name of item clicked",
"Variable1": "Some bit of information",
"Variable2": "Some other bit of information",
...
...
내가 할 노력하고있어 모든 예에서 돌아 오게해야 results[0].value
또는 results[0].attributes.name
은 "항목의 이름을 클릭"중 하나를 반환합니다. layerId, layerName, value 및 displayFieldName은 "가장 많이 액세스되는 데이터"이므로 반환되지만 동일한 정보가 속성 내에도 있습니다.
나는 console.log(results[1].attributes.name);
과 console.log(results)
을 시도했지만 성공하지 못했습니다.
최상위 레벨 객체는'results' 속성을 가지고있다. –
[Access/process (nested) 개체, 배열 또는 JSON] (http://stackoverflow.com/questions/11922383/access-process-nested-objects-arrays-or-json) –
당신은 최상위 수준은 항상'결과' 이 json 객체가 반환 될 때 '결과'도 사용됩니다. 결과는'results.results [0] .value'가 작동 할 것이라고 제안하는 것입니다. 즉, 위의 예에서 응답을 제공했다면 대답은'results.response [0] .value'일까요? – HPWD