JSON

Christian Harms's picture

How many angry birds defeat how many pigs in google+?

Coding (in spare time) should be fun. Some times I change this with real gaming like the angry birds on google+. But after some days of scoring agains my friends I opened the HttpFox plugin and looked behind the normal interface.

And I got a view of the JSON-data files from the angry birds game. Every level is offered in a single json-file and has count for the 1-, 2- or 3-star assessment. With some python scripting I fetched all level files from the app enginge instance of angry birds.

  1. import json, urllib
  2. for level in range(1,9):
  3.   for stage in range(1, level <6 and 22 or 16):
  4.     #url is shorted to prevent copy/paste kiddies ...
  5.     lvUrl = "https://r3138-dot-xxxx.appspot.com/cors/fowl/json/Level%d-%d.json" % (level, stage)
  6.     data = json.loads(urllib.urlopen(lvUrl).read())
  7.     print "You need %s points for 3 stars in level %d-%d." % (
  8.                data["scoreGold"], level, stage)

That's was so easy - all work was done.

And the answer to the question (for all 8 levels and the Chrome level):Read more

Matthias Reuter's picture

The art of escaping

Escaping is the art of transforming a text into a transport format from which it can be extracted again without any modification.

That's something every developer does - to a certain level. For example take the sentence

Matthias says: "I love Javascript".

Now put this sentence in a Java source code:

String s = "Matthias says: "I love Javascript".";

If you don't complain about this, your compiler will. In Java (any many other programming languages) the quotation mark " has a special meaning, it defines a string. So if you have a string containing the quotation mark, you need to escape it:

String s = "Matthias says: \"I love Javascript\".";

If you print out s, the original text is shown:

System.out.print(s); // Matthias says: "I love Javascript".
Read more

Syndicate content