-1

I got json array as output. could anyone explain me how to get indivual value from it for eg( C:/). The following is the json array

{"Name":["C:\/","D:\/","E:\/","F:\/","G:\/","My Documents","Microsoft Outlook","Microsoft Outlook Express","Opera","Mozilla","Internet Explorer Settings","FireFox","Desktop","Registry","SystemState"],"path":["C:\/","D:\/","E:\/","F:\/","G:\/","\/\/\/My Documents\/\/\/","\/\/\/Microsoft Outlook\/\/\/","\/\/\/Microsoft Outlook Express\/\/\/","\/\/\/Opera\/\/\/","\/\/\/Mozilla\/\/\/","\/\/\/Internet Explorer Settings\/\/\/","\/\/\/FireFox\/\/\/","\/\/\/Desktop\/\/\/","\/\/\/Registry\/\/\/","\/\/\/SystemState\/\/\/"],"hasChild":["1","1","1","1","1","0","0","0","0","0","0","0","0","0","0"]} 
suriya
  • 13
  • 3

2 Answers2

0

Assuming your language is JavaScript, you first need to parse the JSON (below I use jQuery's $.parseJSON method) and then access the appropriate property and array position. To retreive "C:\", you would do this:

var sJSON = '{"Name":["C:\/","D:\/","E:\/","F:\/","G:\/","My Documents"]}';
var oJSON = $.parseJSON(sJSON);
alert(oJSON.Name[0]); //displays C:\

If you're using JavaScript, you can use an eval() statement in place of a $.parseJSON because JSON is executable in JavaScript, but it is safer to use a $.parseJSON.

More on JavaScript eval(): When is JavaScript's eval() not evil?

Community
  • 1
  • 1
Elliot B.
  • 17,060
  • 10
  • 80
  • 101
0

Use a JSON parsing library for your language.

In JavaScript, you can use JSON.parse. If your output is in the var output, you would do:

var obj = JSON.parse(output);
console.log(obj.path[0]);
w00t
  • 17,944
  • 8
  • 54
  • 62