dongxixian7803 2012-07-24 00: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 01: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.

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

报告相同问题?