Accessing JSON Object not working

Vinicius Luz
Tera Expert

Hello guys, can you notice something wrong in this script? It is returning a string and when I try to access it in the client side, even parsing with JSON.parse, I cannot access the obj elements...

Script include:

 

find_real_file.png

OnChange client script:

find_real_file.png

1 ACCEPTED SOLUTION

-O-
Kilo Patron
Kilo Patron

response.getBody() returns a string, so you shouldn't "stringify" it - it is already a string.

An advice, if you allow me: post text, not pictures.

Someone might want to test your code, should that person re-type what you already have? How many do you thing would go the length?

View solution in original post

6 REPLIES 6

-O-
Kilo Patron
Kilo Patron

response.getBody() returns a string, so you shouldn't "stringify" it - it is already a string.

An advice, if you allow me: post text, not pictures.

Someone might want to test your code, should that person re-type what you already have? How many do you thing would go the length?

Thanks a lot, it worked.
And thanks for the advice, I'll take it.

You're welcome, I'm glad it works! 🙂

Hitoshi Ozawa
Giga Sage
Giga Sage

getXMLAnswer() returns a string and not an object so can's do answerParsed.logradouro.
Would need to do ga.getXML(HelloWorldParse);

ga.getXMLAnswer(HelloWorldParse);

function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('street', answerPrsed.logradouro);
g_form.setValue('city', answerParsed.localidade);
}

If the value is not being returned from script include, the most common cause is the object returned is not created properly.

When creating an array, use .toString().

e.g.
var jsonData = [];
jsonData.push(gr.street.toString());   // convert object to string

Return a JSON.stringify(array).

return JSON.stringify(jsonData);