1

我正在尝试在 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。有没有一种简单的方法可以删除这些引号?

4

3 回答 3

2

首先,您似乎需要在 Trialpay 的网站上完成应用程序的配置,因此URL_TO_APP_CURR_WEBPAGE. 这里的问题可能是您尚未将应用配置完成到生成有效 JSON 所需的程度。

但是,如果这不是答案,如果您仍然收到无效的 JSON(我同意,那是无效的),我建议您联系您的 Trialpay 代表。他们通常反应灵敏,我们在游戏开发过程中确实发现了他们产品的一些问题。

祝你好运 - 如果/当您找到更多信息时,请在此处回复。

干杯

于 2012-05-10T18:38:50.193 回答
0

您是否尝试json_decode($json_string, true);过将其转换为关联数组。

于 2012-05-10T18:33:55.703 回答
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 我。

于 2012-05-10T22:56:53.593 回答