将 iPhone 应用程序交易收据信息解码为 PHP 数组
{ “签名” = “Alof/CEJ8a==”; “购买信息”=“ewoJIml0”; “环境”=“测试”; “豆荚”=“100”; “签名状态”=“0”; }
将 iPhone 应用内购买交易帖子解析为数组的最佳方法是什么?谢谢。
{ "signature" = "Alof/CEJ8a=="; "purchase-info" = "ewoJIml0";
"environment" = "Test"; "pod" = "100"; "signing-status" = "0"; }
What is the best way with PHP to parse this iPhone in-app purchase transaction post into an array? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不确定这是“最好”的方法,但这是一种方法。由于数据字符串由公共字符分隔(每个键/值由
;
设置,然后键/值之间有=
),因此大部分解析可以是使用explode()
完成。您可以使用trim()
- 使用自定义字符列表 - 删除整个字符串以及键/值周围的额外字符。请注意,这将期望键永远不会有
=
(尽管值可能):输出:
Not sure this is the 'best' way, but it's one way. Since the data string is separated by common characters (each key/value set by a
;
, then an=
between the key/value), the bulk of the parsing can be done withexplode()
. And you can usetrim()
- with a custom character list - to remove the extra characters around the whole string, and the keys/values.Note that this will expects that a key never has a
=
(although a value may):Output:
您可以将 = 替换为 : 并将 ; 替换为 , ,然后使用 json_decode()。
像这样:
查看此处。
You could replace the ='s with :'s and the ;'s with ,'s and then use json_decode().
Like so:
Check it out here.
输出:
Output: