sptrsn Posted May 19, 2012 Share Posted May 19, 2012 I'm trying the fetch some geocode data from mapquest. Google doesn't like me right now. I keep running into the query_limit. So I want to set a back up that will go into production when I get that error from the big G. I have my api key and I can put the string in a var. $geocode = file_get_contents($url) I selected json as the output and when I echo $geocode... here is the first portion of the string....(I want lat & lng) renderOptions({"results":[{"locations":[{"latLng":{"lng":-112.35984,"lat":34.58752},..... Now for the life of me, I can't do anything with it. I've tried json_decode() with the true argument there and not. $output = json_decode($geocode, true); $output = json_decode($geocode); vardump($output) is NULL. So, I thought, well maybe I don't need to decode it, but I can't figure out how to parse it. I'm lost. This admittedly is my first attempt as trying to work with a jason object, but jeesh, it doesn't seem like it should be that hard. Can someone start me in the right direction? Quote Link to comment https://forums.phpfreaks.com/topic/262755-json-newb-cant-parse-this-string/ Share on other sites More sharing options...
ManiacDan Posted May 19, 2012 Share Posted May 19, 2012 Can we see all of this string? Quote Link to comment https://forums.phpfreaks.com/topic/262755-json-newb-cant-parse-this-string/#findComment-1346738 Share on other sites More sharing options...
requinix Posted May 19, 2012 Share Posted May 19, 2012 If the string actually includes "renderOptions" then you're pulling from the wrong page. You should be getting strictly JSON back: {"results":[{"locations":[{"latLng":{"lng":-112.35984,"lat":34.58752},..... Quote Link to comment https://forums.phpfreaks.com/topic/262755-json-newb-cant-parse-this-string/#findComment-1346739 Share on other sites More sharing options...
sptrsn Posted May 19, 2012 Author Share Posted May 19, 2012 I was actually just stripping the renderOptions portion of the string. Here is the entire result.. renderOptions({"results":[{"locations":[{"latLng":{"lng":-112.35984,"lat":34.58752},"adminArea4":"Yavapai County","adminArea5Type":"City","adminArea4Type":"County","adminArea5":"Prescott Valley","street":"3037 N Kings Hwy W","adminArea1":"US","adminArea3":"AZ","type":"s","displayLatLng":{"lng":-112.3596,"lat":34.58752},"linkId":40959430,"postalCode":"86314-2815","sideOfStreet":"R","dragPoint":false,"adminArea1Type":"Country","geocodeQuality":"POINT","geocodeQualityCode":"P1AAA","mapUrl":"http://www.mapquestapi.com/staticmap/v3/getmap?type=map&size=225,160&pois=purple-1,34.58752,-112.35984,0,0|¢er=34.58752,-112.35984&zoom=12&key=Fmjtd|luua2duynh,rw=o5-hr1xq&rand=1015257776","adminArea3Type":"State"}],"providedLocation":{"location":"3037 N KINGS HWY W,PRESCOTT VALLEY, AZ 86314"}}],"options":{"ignoreLatLngInput":false,"maxResults":-1,"thumbMaps":true},"info":{"copyright":{"text":"© 2012 MapQuest, Inc.","imageUrl":"http://api.mqcdn.com/res/mqlogo.gif","imageAltText":"© 2012 MapQuest, Inc."},"statuscode":0,"messages":[]}}); I trimmed the "renderOptions(" and the closing ");" then tried json_decode. still nothing. Quote Link to comment https://forums.phpfreaks.com/topic/262755-json-newb-cant-parse-this-string/#findComment-1346741 Share on other sites More sharing options...
sptrsn Posted May 19, 2012 Author Share Posted May 19, 2012 Thanks requinix. I reworked the URL, it returned a true json object and now it parses it just fine. That was a goat rodeo! Thanks for the input. Quote Link to comment https://forums.phpfreaks.com/topic/262755-json-newb-cant-parse-this-string/#findComment-1346745 Share on other sites More sharing options...
Ozyank Posted June 16, 2012 Share Posted June 16, 2012 I'm having the same problem myself. How did you rework the "URL". Does it have something to do with the value of the callback parameter? Quote Link to comment https://forums.phpfreaks.com/topic/262755-json-newb-cant-parse-this-string/#findComment-1354379 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.