简体   繁体   中英

how can I access to a specific json value in my returned data

I send a http GET request which returns JSON data in the following form. I am finding it impossible to access this data despite having no problems with example json that I create. I want to ideally take the array under wifi, and use this data to create a html table, but I think I can work out how to create the table if I could just access the actual elements of the data.

I have tried multiple methods to try and reach the first timestamp. I have tried:

var element = result.undefined.clients.wifi[0].timestamp;

but this returns an error that 'clients' can't be found.

I also tried:

var element = result.clients.wifi[0].timestamp; //and
var element = result.wifi[0].timestamp;

The JSON data returned to a variable is shown below:

result = undefined {"sourceId":"idid","sourceType":"CLOUD_source","searchMeta":{"maxResults":4,"metricType":["clients"],"family":["wifi"],"Interval":"M1"}, "clients":{"wifi": [{"timestamp":1424716920,"avg":3,"min":1,"max":4,"Count":8,"sCount":3,"sources":["x1","x2","x3","x4","x5","x6","x7","x8"]},{"timestamp":1424716980,"avg":2,"min":1,"max":3,"Count":4,"sCount":2,"sources":["x3","x4","x8","x4"]},{"timestamp":1424717160,"avg":2,"min":1,"max":3,"Count":9,"sCount":4,"sources":["x3","x4"]}]}}

The JSON data is invalid. If it is returned from a server, you need to go there and correct the data source, (if you have access to that).

Otherwise, perhaps notify the backend guy(s) about it.

If it is from a REST API, and you are "sure" that the server code should be error free, then check that you have supplied all the required parameters in the API request you are making.

I think your JSON is messed up. I ran it through JSONLint, and having the undefined at the beginning causes things to break.

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