I am trying to port this bit of Python code to Java http://www.bemasher.net/archives/1002 (scroll down to the bottom for the code)
But because everything is dynamically typed, I’m having difficulty porting this. I need to be able to use a Java implementation of Pythons json. Right now I’m using gson ( http://code.google.com/p/google-gson/ ), but I’m open to anything.
Neither of gson’s fromJson’s signatures
public <T> T fromJson(String json, Class<T> classOfT) throws JsonParseException
public <T> T fromJson(String json, Type typeOfT) throws JsonSyntaxException
match Pythons
data = json.loads(response)
This is the JSON that I am trying to read: http://www.ows.newegg.com/Stores.egg/Categories/1
How would I go about getting the class or type of the JSON above and read through it? All the other examples I’ve seen you have to know what it is.
Thanks!
It basically fetches
http://www.ows.newegg.com/Stores.egg/Menusand dumps its contents to a string (response), then it parses the JSON usingjson.loads()and puts that intodata.Then it will iterate through the contents of data and build a HTML list using
lxml. The list itself should look like:Where
{StoreID}and{StoreTitle}are the IDs and titles fetched and parsed from that URL.References:
urllib2,json,lxml