简体   繁体   中英

Retrieve the value from a JSONP formatted data object

Just when I think I've got he hang of identifying an element in an object, I run into a scenario that I cannot seem to get the value I want.

This part works and the data returned is correct: I have a map and when I attempt to identify a building on the map, I receive the following json object (this has been shortened for readability but in real life, its properly formatted) : The function MapClick(queryResults) is called when the map is clicked.

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",
            ...
            ...

All I'm trying to do is return either the results[0].value OR results[0].attributes.name which in this example should bring back "Name of item clicked". The layerId, layerName, value, and displayFieldName are the "common most accessed data" so they are returned but the same information is also found within the attributes.

I've tried console.log(results[1].attributes.name); and console.log(results) with no success.

原来处理MapClicked的函数的名称是需要queryResults,所以正确的答案是: queryResults[0].value并且当您看到方括号[ ,您可以确定将需要[一些数字] (例如queryResults[0].valuequeryResults[99].someothervariable ,或者至少我认为这是正确的声明。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM