0

Hi, I've got this string when parsed a web page.

string(41) "_result_ = {status:"OK",
id:"30025",
name:"John Doe",
location:"India"}"

I believe that this code is JSON. but when I use json_decode() , it returns NULL. Someone Please help me parse this string. Thank you. :)

2
Contributors
4
Replies
19
Views
3 Years
Discussion Span
Last Post by suraj32
0

Hello pzuurveen, I've done like this. But, still I get NULL output. Can you please check it?

$var = preg_replace("/_result_=/", "", $result);
$var =trim($var,'"'); //quotes Free String
$output = json_decode($var);
var_dump($output);
//Output is NULL
1

in json the name also has to be inside "", I foreget about that.
Gess that you have to write your own parser.
something like:

    $var = preg_replace("/_result_=/", "", $var);
    $var =trim($var);
    $var =trim($var,'{'); //remove {
    $array = explode (",", $var);
    $result=array();
    foreach ($array as $var2)
        {
        $array2=explode(':',$var2);
        $result[$array2[0]]=$array2[1];
        }  
    var_dump ($result);

Edited by pzuurveen

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.