Monday, 17 April 2017

Parsing JSON Array with Node.js [duplicate]

This question already has an answer here:

Im new to node.js and I can not figure out how to parse the following JSON structure:

{"ss":[ ["Sun","YYY","10","XXX","27","57142","17","16"],["Sun","AAA","20","BBB","24","57144","17","20"] ]}

I have the following so far.

if (!error && response.statusCode === 200) {    
   console.log(body) // Print the json response
try { 
      var profile = parseJson(body); 
      console.log(profile) 
    } catch(error) { 
      console.log("ERROR 1")
    }
} else {
   console.log("ERROR 2")
}

The output at the first console.log (console.log(body)) outputs the entire JSON array as desired.

After that the parseJson(body) does not work and the "Error 1" is thrown and caught.

Can anyone provide any insight!?



via iosforme

No comments:

Post a Comment