2015-03-25 41 views
0

我試圖從Recognize(時尚識別)API詢問API響應。數據如下所示返回。我試圖從下面的對象中提取服裝項目。在JavaScript中提取對JSON對象的API響應的特定部分

Object {data: " Array↵(↵ [id] => 1309↵)↵{"Status":true,"Data":{"VufindTags":["Dress"," Purse"]}}", status: 200, headers: function, config: Object, statusText: "OK"}config: Objectdata: " Array↵(↵ [id] => 1309↵)↵{"Status":true,"Data":{"VufindTags":["Dress"," Purse"]}}"headers: function (name) {status: 200statusText: "OK"__proto__: Object 

我曾嘗試使用data.data其返回以下作爲字符串來訪問:

" Array 
(
[id] => 1309 
) 
{"Status":true,"Data":{"VufindTags":["Dress"," Purse"]}}" 

我然後試圖用JSON.parse從VufindTags提取數據。這沒有用。

有沒有辦法將其轉換成JSON對象?

感謝您的任何幫助!

回答

1

它看起來像vufind API給你的PHP print_r輸出,而不是JSON。最好的辦法是讓他們修正他們的API。如果不這樣做,你可以將JSON查詢位拖出來。我取得了一些成功的:

myObj = JSON.parse(apiOutput.slice(apiOutput.indexOf('{'))) 

...但我不會將它放入一個應用程序,並調用它的生產做好準備,特別是當API顯然不會給你什麼應該擺在首位。

+0

非常感謝您的幫助!你的代碼解決了我的問題!最好的祝願 – Vinisha 2015-03-25 13:42:43