2016-01-22 61 views
-2

访问JSON对象,在我的代码的承诺之一,返回结果这样如何从阵列

[{"success":true,"fileName":"./tmp/test.txt"}] 

,我想将其转换成JSON。如何转换它? 输出: - {“success”:true,“fileName”:“./ tmp/test.txt”}

+2

data [0] .fileName?或者我错过了你的问题? –

+2

'var a = [{“success”:true,“fileName”:“./ tmp/test.txt”}];''console.log(a [0] .fileName)' –

+0

@VickyGonsalves,都使用'a'作为数组变量名?? –

回答

-1

您只需将数组中的项目定位到整个'fileName'即可:

arrayName[1] 

希望这有助于

感谢

+0

这会回来'undefined'('var arrayName = [{“success”:true,“fileName” :“./ tmp/test.txt”}]; arrayName [1]; // undefined') – putvande

0

收到包含一个对象的数组。 只需访问阵列的第一个元素,如:

var array = [{"success":true,"fileName":"./tmp/test.txt"}]; 
var fileName = array[0].fileName; 
+0

你应该编辑你的答案,因为写入它将不起作用('a'应该是未定义的) –

+0

@AntoninM。完成! –