2012-08-25 55 views
-1

我得到了json數組作爲輸出。任何人都可以向我解釋如何從例如(C:/)中獲得個人價值。以下是JSON數組如何從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"]} 
+1

你使用哪種語言? –

回答

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,您可以代替$.parseJSON的使用eval()語句,因爲JSON是在JavaScript中的可執行文件,但它是更安全使用$.parseJSON

更多關於JavaScript的eval()When is JavaScript's eval() not evil?

0

使用JSON解析庫您的語言。

在JavaScript中,you can use JSON.parse。如果你的輸出在var output中,你應該這樣做:

var obj = JSON.parse(output); 
console.log(obj.path[0]);