user6289857 user6289857 - 10 months ago 54
PHP Question

How to Convert JSONP data to PHP Array

The following output JSONP I'm receiving from the third part API.

"website": {
"name": "",
"malwareListStatus": "listed",
"partialMalwareHosts": [],
"uwsListStatus": "unlisted",
"partialUwsHosts": [],
"socialListStatus": "unlisted",
"partialSocialEngHosts": [],
"malwareDownloadListStatus": "unlisted",
"partialMalwareDowHosts": [],
"uwsDownloadListStatus": "unlisted",
"partialUwsDowHosts": [],
"unknownDownloadListStatus": "unlisted",
"partialUnknownDowHosts": [],
"numAses": 1,
"numListedTimes": 1,
"asList": ["AS28716 (RETELIT-AS)"],
"malwareSite": {
"type": 6,
"sendsToAttackSites": [],
"sendsToIntermediarySites": [],
"receivesTrafficFrom": ["", "", ""]
"as": {},
"dataUpdatedDate": 1462333750,
"lastVisitDate": 1462321226,
"lastMaliciousDate": 1462321226,
"numTested": 14484

I'm trying to use
to convert into the PHP array. However, It is not working. Do you have any pointers ?


The fastest way would be to do just a simple str_replace() to get rid of the function name and the last curly brace in the Response. Otherwise you don't get valid JSON and that's why your json_decode() fails.