A follow up to: https://stackoverflow.com/posts/13303108 where all the responses suggested JS
Is there a function of some sort to take the following and fix it with php when it occurs so that the output will be vaild json? front end (js) is not an option. The issue seems to be the number leading into the array not being quoted or something to that end. I cannot fix the source either.
{
29646191: [
"https://www.facebook.com/RobertScoble/posts/480030845352725",
"https://sphotos-a.xx.fbcdn.net/hphotos-prn1/s480x480/546943_10151235934049655_1771118951_n.jpg",
"Today I tried... | Facebook",
"Robert Scoble wrote: Today I tried something. I paid $49 and... Join Facebook to connect with Robert Scoble and others you may know.",
null,
[
"//images3-focus-opensocial.googleusercontent.com/gadgets/proxy?url\u003dhttps://sphotos-a.xx.fbcdn.net/hphotos-prn1/s480x480/546943_10151235934049655_1771118951_n.jpg\u0026container\u003dfocus\u0026gadget\u003da\u0026rewriteMime\u003dimage/*\u0026refresh\u003d31536000\u0026resize_h\u003d150\u0026resize_w\u003d150\u0026no_expand\u003d1",
150,
150,
null,
null,
null,
null,
null,
[
3,
"https://images1-focus-opensocial.googleusercontent.com/gadgets/proxy?url\u003dhttps://sphotos-a.xx.fbcdn.net/hphotos-prn1/s480x480/546943_10151235934049655_1771118951_n.jpg\u0026container\u003dfocus\u0026gadget\u003dhttps://plus.google.com\u0026rewriteMime\u003dimage/*\u0026resize_h\u003d800\u0026resize_w\u003d800\u0026no_expand\u003d1"
]
],
"//s2.googleusercontent.com/s2/favicons?domain\u003dwww.facebook.com",
[],
null,
[]
]
}
Edit: the very base functions do not work here (json encode/decode). It had to have been taken from a source and run through many things for php to even start to be able to handle it.
To wit, this is the code that handles it before this
$instring = false;
$inescape = false;
$lastchar = '';
$output = "";
for ( $x=0; $x<strlen( $sourcejson ); $x++ ) {
$char = substr( $sourcejson, $x, 1 );
//toss unnecessary whitespace
if ( !$instring && ( preg_match( '/\s/', $char ) ) ) {
continue;
}
//handle strings
if ( $instring ) {
if ( $inescape ) {
$output .= $char;
$inescape = false;
} else if ( $char == '\\' ) {
$output .= $char;
$inescape = true;
} else if ( $char == '"' ) {
$output .= $char;
$instring = false;
} else {
$output .= $char;
}
$lastchar = $char;
continue;
}
switch ( $char ) {
case '"':
$output .= $char;
$instring = true;
break;
case ',':
if ( $lastchar == ',' || $lastchar == '[' || $lastchar == '{' ) {
$output .= 'null';
}
$output .= $char;
break;
case ']':
case '}':
if ( $lastchar == ',' ) {
$output .= 'null';
}
$output .= $char;
break;
default:
$output .= $char;
break;
}
$lastchar = $char;
}