codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
<?php //header('Content-type: text/plain; charset=UTF-8'); $j1 = ' ({serverTimestamp: "Wed, 28 Mar 2012 11:40:26 +0000",users: [{userId: "username",statuscode:0,floatingPL:-1000.00,balance:50000,equity:40000,freeMargin:4000,marginInUse:30.11,currency:"EUR",closedPL:5692.85,creditFacility:0,mostRecentUpload:"Wed, 28 Mar 2012 11:39:58 +0000"}]}) '; $j2 = '{ aaa: "a\"b\"c",bbb:"ab\"c", "cc\"cc":"ccc" }'; function fix_json( $j ){ $j = trim( $j ); $j = ltrim( $j, '(' ); $j = rtrim( $j, ')' ); $a = preg_split('#(?<!\\\\)\"#', $j ); for( $i=0; $i < count( $a ); $i+=2 ){ $s = $a[$i]; $s = preg_replace('#([^\s\[\]\{\}\:\,]+):#', '"\1":', $s ); $a[$i] = $s; } //var_dump($a); $j = implode( '"', $a ); //var_dump( $j ); return $j; } var_dump( json_decode(fix_json($j1))); var_dump( json_decode(fix_json($j2)));
Private
[
?
]
Run code
Submit