Can you read a json and get all the strings without knowing what's inside? [duplicate]

0

I'm doing a dynamic form where I get a Json and I create a dynamic form, it's all automated, except the part that I have to extract every string from the JSon and put inside a array .

    
asked by anonymous 16.06.2015 / 22:30

1 answer

0

Think like this:

This is an object: { } , and this is an array: []

Every "JSON" output is considered an object. Even the array in JavaScript is seen with an Array-only object.

In case, when you receive a collection in "JSON" with keys and assigns a name to these keys: var obj = { nome: "x", id: "y" } The correct way to access your "x" and "y" values is by calling the object obj: .name, obj.id. The same can be done in another way, as done in the array, however this is valid in cases where the keys will be dynamic: obj["nome"]; obj["id"];

Now think that if you want to receive a JSON as a string, it's the same as ignoring all these rules. Then you just get the whole object, and convert it to a string, so use the method JSON.stringify(obj) ;

    
17.06.2015 / 00:17