cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can change your system assigned username to something more personal in your community settings. X

Error in Reading Json Element with dash "-"

pcheah
8-Gravel

Error in Reading Json Element with dash "-"

hi,

Did anyone have the same problem also. It seems like the Javascript in ThingWorx cannot read the "-" as Element's name.

e.g. of Json:

{

"dataName-something": "1" ;

}

Thanks. Hope to find a solution here.

3 REPLIES 3
PaiChung
22-Sapphire I
(To:pcheah)

How are you trying to read it?

You should be able to use something like jsonObject["dataName-something"] or jsonObject.["dataName-something"]

I tried below code and it works fine for me.

var myObject = {"Sample-Check" : "10"};

var result = myObject["Sample-Check"];

With B/R,

Praveen

pcheah
8-Gravel
(To:pcheah)

Hi all,

Thanks for your help.

It is working by inserting the ["dataName-something"] to the code.

e.g.

var response=Resources["ContentLoaderFunctions"].GetJSON(params)["dataName-something"] ;

Top Tags