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

Error in Reading Json Element with dash "-"

pcheah
Regular Member

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

Re: Error in Reading Json Element with dash "-"

How are you trying to read it?

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

Re: Error in Reading Json Element with dash "-"

I tried below code and it works fine for me.

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

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

With B/R,

Praveen

Re: Error in Reading Json Element with dash "-"

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"] ;

Announcements

Check out the upcoming Expert Session: Understanding ThingWorx Navigate Licensing in Community "Customer Events" section.