doushao1087 2016-08-17 06:05
浏览 51

如何解码json对象

This might be simple to some but a challenge to me. Well from a documentation, I am getting JSON object in the body of the POST request. The format is shown below.

Question how do I decode the json object when they have not given the variable name of the json object. I thought I would get a variable name so that I would decode this way $data = json_decode($jsonFromSource);

I can not figure out a way to do the same, anyone? Thanks.

Direction from documentation: The POST request will be sent to a URL provided by the enterprise. The following POST parameters that will be passed will be as follows
The parameters passed above will be contained in a JSON object in the body of the POST request.
Link to the brief documentation https://app.kopokopo.com/push_api

{
   "service_name" : "MPESA",
   "business_number" : "888555",
   "transaction_reference" : "DE45GK45"
   "internal_transaction_id" : 3222
   "transaction_timestamp" : "2013-03-18T13:57:00Z"
   "transaction_type" : "Paybill"
   "account_number" : "445534"
   "sender_phone" : "+254903119111"
   "first_name" : "John"
   "middle_name" : "K"
   "last_name" : "Doe"
   "amount" : 4000
   "currency" : "KES"
   "signature" : "dfafwerewKkladaHOKJdafdf"
}
  • 写回答

1条回答 默认 最新

  • 普通网友 2016-08-17 06:10
    关注

    I am not sure how you are initially retrieving the data - perhaps this will help?

    $url='http://www.example.com/api/feed.json';
    $data=file_get_contents( $url );
    $json=json_decode( $data,true );
    foreach( $json as $param => $value ) echo $param, $value, '<br />';
    
    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100