How to do JSON parsing to get api_keys | ThingSpeak API | Forum

Avatar

Please consider registering
Guest

Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

Register Lost password?
sp_Feed sp_TopicIcon
How to do JSON parsing to get api_keys
Avatar
AnushaPoola
New Member
Forum Posts: 1
sp_UserOfflineSmall Offline
1
February 2, 2017 - 6:27 am
sp_Permalink sp_Print

Hello,

        I am new to thingspeak.I am trying to Parse the Json values of a channel.I tried for the description and metadata and got it.Now i am trying to get the api_keys but i am unable to do it.I am adding the code that i used to parse.with this below code i am getting the error (Uncaught SyntaxError: Unexpected token [ in JSON at positon 1).Can anyone help me how to Parse JSON api_key values,Thankyou.

CODE:-

var obj,ak ;
ak="";
for (var i=0; i<json.length; i++) {
obj = json[i];
if (obj == null || obj == "") {
window.alert("
The "+(i+1)+"th object is NULL/BLANK.");
} else {
if (obj.id == did) {

if (obj.api_keys == null || obj.api_keys == "") {
window.alert("
The api_keys portion of "+(i+1)+"th object is NULL/BLANK.");
} else {
ak = JSON.parse("{" + obj.api_keys + "}");
console.log("
The deails of "+(i+1)+"th Object are :
Apikey : " + ak.api_key + "
WriteFlag : " + ak.write_flag );
}

Avatar
rw950431

Forum Posts: 250
sp_UserOfflineSmall Offline
2
February 11, 2017 - 11:11 pm
sp_Permalink sp_Print

Did you try to print the whole json object and each array member in turn using console.log()? 

 

I often use http://jsonlint.com/ to check if json is properly formatted or not.

Avatar
zoey7
New Member
Forum Posts: 2
sp_UserOfflineSmall Offline
3
September 6, 2017 - 12:17 am
sp_Permalink sp_Print

I use this tool to check JSON format: JSON Formatter

Avatar
ezmaintain
New Member
Forum Posts: 1
sp_UserOfflineSmall Offline
4
October 21, 2017 - 11:57 pm
sp_Permalink sp_Print

Yes JSON Formatter is good tool

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
19 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 250

Vinod: 154

cstapels: 83

piajola: 75

vespapierre: 63

Adarsh_Murthy: 59

Newest Members:

webone

KMVp

aamir786

sugengprayogi

vickysam@gmail.com

farmerkjs

Forum Stats:

Groups: 4

Forums: 17

Topics: 1289

Posts: 4481

 

Member Stats:

Guest Posters: 1

Members: 5652

Moderators: 0

Admins: 2

Administrators: Hans, lee