-1

我得到了 json 数组作为输出。谁能解释我如何从中获得个人价值,例如(C:/)。下面是json数组

{"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"]} 
4

2 回答 2

0

假设你的语言是 JavaScript,你首先需要解析 JSON(下面我使用 jQuery 的$.parseJSON方法),然后访问相应的属性和数组位置。要检索“C:\”,您可以这样做:

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

如果您使用的是 JavaScript,则可以使用eval()语句代替 a,$.parseJSON因为 JSON 在 JavaScript 中是可执行的,但使用$.parseJSON.

更多关于 JavaScript的内容eval()JavaScript 的 eval() 什么时候不是邪恶的?

于 2012-08-25T07:51:17.560 回答
0

为您的语言使用 JSON 解析库。

在 JavaScript 中,您可以使用 JSON.parse。如果您的输出在 varoutput中,您将执行以下操作:

var obj = JSON.parse(output);
console.log(obj.path[0]);
于 2012-08-25T07:52:02.717 回答