Re: [Q] am i using the right json feed?

61 views
Skip to first unread message

Alan

unread,
Apr 20, 2013, 12:26:38 PM4/20/13
to massdotd...@googlegroups.com
You're getting back an HTML webpage.  I can tell because "<!DOCTYPE" is the beginning of an HTML page, so JSON would not begin with this.  That is why everyone is telling you that you're passing in the wrong URL.  The URL appears correct though, and I can load JSON from it, so I don't know what is wrong.  There are a few possibilities that come to mind:
  1. You're not actually passing in the URL correctly.  Maybe you are passing it in quoted and it shouldn't be.  Maybe the URL is supposed to be encoded and you're passing it in unencoded.   See if you can find a tutorial that uses getJSONFromUrl and make sure you're doing the same thing.
  2. getJSONFromUrl is broken and not doing the right thing.  I have no idea what this is or whether it works, so I wouldn't rule it out.  If it's part of the Android standard library this likely isn't the case, though.
  3. There's something about your request that is causing JSON to come up in the browser when we test it, but the MBTA site is returning HTML indicating an error when you make the request from the Android code.  In order to test this, I would download Fiddler and use it to trace EXACTLY what HTTP request is being made when you type the JSON URL into the browser and exactly what request is being made when you execute your code.  There will be a difference and that will help you figure out why the response is HTML.  Also, you can look at the full response that you get back from the MBTA server in the Android code case and see if there's an error that is illuminating at all.
Good luck.

-alan

On Tuesday, April 16, 2013 9:14:57 PM UTC-4, Parag Thuse wrote:
Hello fellow mbta developers,

im trying to build a app for commuter rail that i take every day, im doing this partly to learn this aspect of android with the added bonus of knowing where the train exactly is...

im using the following url: "http://developer.mbta.com/lib/RTCR/RailLine_8.json" -- framingham/wrocester line

im using a helper JSON parser class and when i run the debugger over this line: JSONObject json = jParser.getJSONFromUrl(url); i get the follow error: 04-17 00:58:36.383: E/JSON Parser(1241): Error parsing data org.json.JSONException: Value <!DOCTYPE of type java.lang.String cannot be converted to JSONObject

i have searched online, and people have said that the url im passing to get the json is not right...hence im here asking for any insight on this...

Any help is appreciated!
Parag


Reply all
Reply to author
Forward
0 new messages