dongxixian7803 2012-07-24 08:03
浏览 66
已采纳

使用php解析json就像数据一样

I have some Json like data got crawling a URL

[[["oppl.lr",[,,,,,,,,,,,[[[[[,"A Google User"]
,,,,1]
,3000,,,"Double tree was ok, it wasnt super fancy or anything. Its good for families and  just relaxing by the pool. Service was good, and rooms were kept neat.","a year ago",["http://www.ma..",,1],,"","",""]
]
,["Rooms","Service","Location","Value"]
,[]

Which is impossible to parse using php json_decode() function. Is there any library or something which will allow me to convert this to a regular json so that my task will be easier ? Otherwise I know I have to write regular expression.

Thanks in advanced.

  • 写回答

1条回答 默认 最新

  • doujinai2183 2012-07-24 09:25
    关注

    Based on your comment. Incase your data is

    [["oppl.lr",[,,,,,,,,,,,[[,"A Google User"],"",""],""]]]

    If you can somehow send the data to client side. Then it is a valid javascript array. Either you can process the data @client side or use

    JSON.stringify([["oppl.lr",[,,,,,,,,,,,[[,"A Google User"],"",""],""]]]);

    and send the data back to server as

    "[["oppl.lr",[null,null,null,null,null,null,null,null,null,null,null,[[null,"A Google User"],"",""],""]]]"

    Else via php you can use this function

    function getValidArray($input) {
       $input = str_replace(",,", ',"",', $input);
       $input = str_replace(",,", ',"",', $input);
       $input = str_replace("[,", '["",', $input);
       return eval("return $input;");
    }
    

    You can optimize the above function as per the need.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口