I searched high and low for a similar question but nobody seems to like it.
I am trying to retrieve a JSS from an API URL and converting it into a php companion array.
The API returns the URL:
{"requestdetails": "{Category: = 0, position = all, fromindex = 0}", "status": "success "," Recent_campaign ": [{" campaign_key ":" 34 "," sent_date_string ":" February 11, 2014, 11:00 am, "" sent_time ":" 1392145200000 "," campaign_name ":" sales: sports ( 11/02/14), "created_datasstring": "11 February 2014, 09:40 am", "campaign_status": "sent", "" "," normal "," created time ":" 1392140449000 " , "Campaign_preview": ""}, {"campaign_key": "54", "sent_data strings": "February 06, 2014, 11:18 am", sent " "", "Campaign_name": "sales: game (06/02/14)", "created_datestring": "06 February 2014, 11:11 am," "campaign_stats": "sent", " "Type": "Normal", "Created Time": "1391713874000", "Campaign_preview": ""}, {}, "Campaign_code": "20", "Code": "0", "Yuri": "/ API / Recent Campaign", "Version": "1"
}
The code I'm using is:
< Previous> $ url = "http: // api_url"; $ Json = (file_get_contents ($ url)); $ Decode = json_decode ($ json, true); Print_r ($ decode);
But what I get is "Request Details" as a key and all the items under it as a long string. But when I go to the URL manually and copy directly to json, if i json_decode ("stuck json", true); Why does this matter work completely?
As updated in the request, when using file_get_contents, information var_dump (fyi, there are two more results from being listed when I do it but I have reduced them for posting.) :
array (5) {["recent_sent_campaigns"] = & gt; String (5354) "[[campaign_key = 34, sent_date_string = 11 February 2014, 11:00 am, sent time = 1392145200000, campaign_name = sale: game (11/02/14), created_datastring = 11 February 2014, 09:40 am , Campaigntype = normal, created_time = 1392140449000}, {campaign_key = 54, sent_date_string = 17 February 2014, 11:38 am, Posted by = 13 92665920000, campaign_name = Congress, created_data_string = 06 February 2014, 08:39 am, campaign type = Normal, created_time = 1391704770000}] "[" status "] = & gt; String (7) "success" ["code"] = & gt; String (1) "0" ["uri"] = & gt; String (24) "/ api / recentsentcampaigns" ["version"] = & gt; The string (1) "1"}
UPDATE I have reason to believe that this may be due to an apostrophe in one of the campaign_names. Can it happen and if so, how to correct it as I have tried to change the string before decoding but it does not seem to work.
Comments
Post a Comment