douyi5157 2013-11-22 19:54
浏览 31

PHP-Parse this String

I've a got this string after parsing webpage. It looks something similar to this, which is not a valid format of JSON. I was wondering if I can parse this string to get desired values.

string(4747) " _result_ ={status:"OK",loc:"India",
country:{regions:[{ap:"755",mp:"768"},{up:"125",mh:"188"}]},src:"gov"}"

Here you can observe that, the fieldNames doesn't have quotes at all. I've tried to json_decode() which returned NULL. So, Please help me in parsing this string. Thank you.

  • 写回答

3条回答 默认 最新

  • doufeng3602 2013-11-22 19:57
    关注

    The field names don't need to have quotes if they are just single-word strings. The problem is likely right at the beginning:

    " _result_ ="
    

    That's the problem. Try str_replace(' _result_ =', '', $string); and see if it will decode then.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度