I'm doing JSON parser in php for some API that stores informations about estates. I'm getting problem with the parse, since it's returning me NULL vualue instead of an array or object. Simple JSON codes are parsed nicely, but with this:
{"success":true,"totalCount":1,"data":[{"id":996944,"listingId":"2/2089/OMW","mlsId":null,"swoId":null,"sectionName":"ApartmentRental","geoLat":50.06442971278027,"geoLng":19.953176730749647,"country":{"id":34,"name":"Polska","code":"PL"},"location":{"id":42955,"name":"/Małopolskie/Kraków/Kraków-Śródmieście","province":"Małopolskie","locality":"Kraków","quarter":"Kraków-Śródmieście"},"street":{"id":138781,"name":"Hugona Kołłątaja","fullName":"ul. Hugona Kołłątaja"},"foreignStreet":null,"foreignLocation":null,"contractType":"Exclusive","ownershipType":"Mortgage","groundOwnershipType":null,"isSpecial":true,"price":{"amount":2700,"currency":"PLN"},"priceBeforeReduction":null,"dateCreated":"2011-10-22 20:32:35","lastUpdated":"2011-10-25 11:51:09","actualisationDate":"2011-10-22 20:32:34","statusChangeDate":"2011-10-22 20:32:34","images":[{"id":6514430},{"id":6514431},{"id":6514432},{"id":6514433},{"id":6514434},{"id":6514435},{"id":6514436},{"id":6514437},{"id":6514438},{"id":6514439},{"id":6514440},{"id":6514441},{"id":6514442},{"id":6514443}],"licenceNumber":null,"description":"Do wynajęcia piękne, przestronne mieszkanie w wysokim standardzie, świeżo po remoncie przy ulicy Hugona Kołłątaja w Krakowie. Znajduje się w bardzo pięknej z zewnątrz i wewnątrz kamienicy. Bardzo dobra komunikacja, duża powierzchnia 85m2 i wysoki standard wykończenia dają poczucie komfortu. Bardzo blisko Rynku Głównego, Hali Targowej i Galerii Kazimierz. Dzięki bardzo dobrze rozwiniętej komunikacji miejskiej możliwość szybkiego dostania się w każde miejsce Krakowa. Blisko wiele punktów handlowych i usługowych.\n\nMieszkanie składa się 3 odzielnych pokoi, przedpokoju, kuchni oraz 2 łazienek i balkonu. Jest możlwość umeblowania mieszkania według Państwa preferencji na koszt Właściciela. Ogrzewanie własne samodzielne. Możliwość podłączenia Internetu i telefonu.\n\n","englishDescription":null,"russianDescription":null,"parentListingId":null,"totalArea":85,"priceM2":{"amount":31.76,"currency":"PLN"},"noOfFloors":null,"floorNo":null,"furnished":true,"auctionStartingPrice":null,"auctionFrom":null,"auctionTo":null,"openDaysFrom":null,"openDaysTo":null}]}
i get: NULL
Although online parser like http://json.parser.online.fr/ is doing the work just fine.
I was using php built-in funcion json_decode, and some more from php.net, done by users.
Here's my php code:
$url="url_to_json";
$str=file_get_contents($url);
$str = substr($str, 1, strlen($str) - 2);
$str = preg_replace("/([a-zA-Z0-9_]+?):/" , "\"$1\":", $str);
$new=(json_decode($new, true));
var_dump($new);
Any ideas?
json_decode()straight on the file's contents? What's with the other code?