2012-05-10 52 views
1

我試圖在Facebook應用上實施TrialPay/Offerwall/Dealspot。在他們documentation他們給什麼樣的JSON看起來像一個例子,他們給你:TrialPay在回調中發送格式錯誤的JSON

{"order_id":9006316682257,"buyer":409697,"app":107032282669135,"receiver":409697, 
"amount":1,"time_placed":1322622026,"update_time":1322622027,"data":"", 
"items":[{"item_id":"0","title":"3 Fred Currency","description":"Make it rain!", 
"image_url":"http:\/\/external.ak.fbcdn.net\/safe_image.php?d=AQDldsPcWsejAJdC&url=http\u00253A\u00252F\u00252Fwww.etftrends.com\u00252Fwp-content\u00252Fuploads\u00252F2011\u00252F10\u00252Fcurrency-trading.jpg", 
"product_url":"","price":1,"data":"{\"modified\":{\"product\":\"URL_TO_APP_CURR_WEBPAGE\", 
\"product_title\":\"Fred Currency\",\"product_amount\":3,\"credits_amount\":1}}"}],"status":"placed"} 

他們說,如果你json_decode它作爲一個數組,你應該得到這樣的:

Array (
    [order_id] => 9006316682257 
    [buyer] => 409697 
    [app] => 107032282669135 
    [receiver] => 409697 
    [amount] => 1 
    [time_placed] => 1322622026 
    [update_time] => 1322622027 
    [data] => 
    [items] => Array (
       [0] => Array (
         [item_id] => 0 
         [title] => 3 Fred Currency 
         [description] => Make it rain! 
         [image_url] => http://external.ak.fbcdn.net/safe_image.php?d=AQDldsPcWsejAJdC&url=http%3A%2F%2Fwww.etftrends.com%2Fwp-content%2Fuploads%2F2011%2F10%2Fcurrency-trading.jpg 
         [product_url] => 
         [price] => 1 
         [data] => {"modified":{"product":"URL_TO_APP_CURR_WEBPAGE","product_title":"Fred Currency","product_amount":3,"credits_amount":1}} 
        ) 
      ) 
    [status] => placed 
) 

它不雖然數據看起來像這樣:

[data] => "{"modified":{"product":"URL_TO_APP_CURR_WEBPAGE","product_title":"Fred Currency","product_amount":3,"credits_amount":1}}" 

JSON在字符串內部導致它無效JSON。是否有直接刪除這些引號的方法?

回答

0

開發在TrialPay這裏。我們可能在我們的文檔網站上有錯別字,我會發一個筆記來仔細檢查。

與此同時,我已經驗證了在完成基於要約的貨幣的基於要約的訂單時,Facebook傳遞給服務器端回調的實際JSON應該是有效的,並且可以正確解碼爲期望的結果以上。

如果遇到此線範圍以外的任何其他問題,歡迎直接ping通我。

編輯:

複製你的代碼和驗證針對JSONLint後,我遇到了一個問題馬上在你提到的點。但是,在\"product_title\"之前刪除不良分行符後,我能夠正確驗證。例如PHP代碼片段包含如下:

<?php 

$order_details = '{"order_id":9006316682257,"buyer":409697,"app":107032282669135,"receiver":409697,"amount":1,"time_placed":1322622026,"update_time":1322622027,"data":"","items":[{"item_id":"0","title":"3 Fred Currency","description":"Make it rain!","image_url":"http:\/\/external.ak.fbcdn.net\/safe_image.php?d=AQDldsPcWsejAJdC&url=http\u00253A\u00252F\u00252Fwww.etftrends.com\u00252Fwp-content\u00252Fuploads\u00252F2011\u00252F10\u00252Fcurrency-trading.jpg","product_url":"","price":1,"data":"{\"modified\":{\"product\":\"URL_TO_APP_CURR_WEBPAGE\",\"product_title\":\"Fred Currency\",\"product_amount\":3,\"credits_amount\":1}}"}],"status":"placed"}'; 
$order_details_decoded = json_decode($order_details, true); 
$order_details_decoded['items'][0]['data'] = json_decode($order_details_decoded['items'][0]['data'], true); 
print_r($order_details_decoded); 

正如我早期提到的,如果什麼都該線程的範圍之內來了,隨時直接ping通我。

+0

感謝羅布,看着FB發給我的回覆與你的反饋相比,看起來我的反斜槓並不是你的反斜槓。如果我想向您發送特定示例,您是否有首選聯繫方式? – keybored

0

你嘗試json_decode($json_string, true);,將其轉換成一個關聯數組。

+0

json_decode是不會幫助,如果JSON是無效的(每運的帖子,它是) – Madbreaks

+0

我的錯誤,我以爲他只是缺少陣旗,並得到了一個對象,但期望的數組。 – Danny

2

首先,它看起來像你需要完成的Trialpay的網站,因此URL_TO_APP_CURR_WEBPAGE配置您的應用程序。這裏的問題可能是您尚未完成您的應用程序配置以至產生有效的JSON。

如果這不是問題的答案但是,如果你仍然得到無效的JSON(這我同意,這是無效的),我建議您聯繫Trialpay代表。他們通常非常敏感,我們在遊戲開發過程中發現了幾個問題。

祝你好運 - 回到這裏後,如果/當你找到更多信息。

乾杯