我正在尝试在Facebook应用程序上实现TrialPay/Offerwall/Dealspot。在他们的文档中,他们给出了一个示例,说明他们发送给您的 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。有没有一种直接的方法可以删除这些引号?
首先,看起来您需要在Trialpay的网站上完成应用程序配置,因此URL_TO_APP_CURR_WEBPAGE
。 此处的问题可能是你尚未完成生成有效 JSON 所需的应用配置。
但是,如果这不是答案,如果您仍然收到无效的JSON(我同意,这是无效的),我建议您联系您的Trialpay代表。 他们通常反应迅速,我们在游戏开发过程中确实发现了他们的产品的一些问题。
祝你好运 - 如果您找到更多信息,请在此处发布。
干杯
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 我。
您是否尝试过将其转换为关联数组json_decode($json_string, true);
。