dpl74687
2015-11-13 18:54
浏览 35
已采纳

JSON Decode返回NULL

I make a curl request to a URL, got this JSON $data back

{"status":200,"message":"Success","data":[{"cpe_mac":"665544332211","device_mac":"223344556677","device_activity":"INACTIVE","dhcp_lease_held":"CONNECTED_DEVICE_DHCP_LEASE_NOT_AVAILABLE","ip_address":"127.0.0.3","vlan_id":1002,"hostname":"babyhost","dhcp_lease_start_time":400,"dhcp_lease_length":600,"interface":"WIRELESS","ssid":"2219","port_ranges":[{"startport":0,"endport":06000:6500}],"last_updated_utc_in_secs":1446061806668}]}

Then, I decode that $raw = json_decode($data, true);

When I print them out I got null

dd($raw); // null


I just want to convert that json to an array and access it.

Any hints on this will be much appreciated !

图片转代码服务由CSDN问答提供 功能建议

我向URL发出curl请求,得到这个JSON $ data

 <代码> { “状态”:200, “消息”: “成功”, “数据”:[{ “cpe_mac”: “665544332211”, “device_mac”: “223344556677”,”  device_activity “:” INACTIVE”, “dhcp_lease_held”: “CONNECTED_DEVICE_DHCP_LEASE_NOT_AVAILABLE”, “IP_ADDRESS”: “127.0.0.3”, “VLAN_ID”:1002, “主机名”: “babyhost”, “dhcp_lease_start_time”:400, “dhcp_lease_length”:600  , “接口”: “无线”, “SSID”: “2219”, “port_ranges”:[{ “startport”:0 “端面管”:06000:6500}], “last_updated_utc_in_secs”:1446061806668}]} 
 <  / code>  
 
 

然后,我解码 $ raw = json_decode($ data,true);

当我打印出来时,我得到 null

dd($ raw); // null


我只想将json转换为数组并访问它。

我们非常感谢您的任何提示!

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • donglie7778 2015-11-13 18:59
    已采纳

    The json that is returned is invalid

    enter image description here

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • dongshan1396 2015-11-13 18:59

    This part:

    [{"startport":0,"endport":06000:6500}]
    

    of your JSON is invalid. The 06000:6500 is not a valid property value. Once I fixed that, json_decode worked properly.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题