fork download
  1. import java.util.HashMap;
  2. import java.util.Iterator;
  3. import java.util.Map.Entry;
  4. import java.util.Set;
  5. import java.util.regex.Matcher;
  6. import java.util.regex.Pattern;
  7.  
  8. public class Main {
  9.  
  10. public static HashMap<String, String> parseEasyJson(String json) {
  11. final String regex = "([^{}: ]*?):(\\{.*?\\}|\".*?\"|[^:{}\" ]*)";
  12. json = json.replaceAll("\n", "");
  13. Matcher m = Pattern.compile(regex).matcher(json);
  14. HashMap<String, String> map = new HashMap<>();
  15. while (m.find())
  16. map.put(m.group(1), m.group(2));
  17. return map;
  18. }
  19.  
  20. public static void main(String[] args) {
  21. String json = "{\"updated_at\":\"2013-05-24T11:00:26Z\"\n"
  22. + "\"created_at\":\"2011-06-28T07:50:25Z\"\n"
  23. + "\"status\":\"HD [XBOX] Call of Duty Black Ops 2 OPEN LOBBY\"\n"
  24. + "\"url\":\"http://w...content-available-to-author-only...h.tv/zetaspartan21\"\n"
  25. + "\"_id\":23170407\n"
  26. + "\"game\":\"Call of Duty: Black Ops II\"\n"
  27. + "\"logo\":\"http://s...content-available-to-author-only...w.net/jtv_user_pictures/zetaspartan21-profile_image-121d2cb317e8a91c-300x300.jpeg\"\n"
  28. + "\"banner\":\"http://s...content-available-to-author-only...w.net/jtv_user_pictures/zetaspartan21-channel_header_image-7c894f59f77ae0c1-640x125.png\"\n"
  29. + "\"_links\":{\"subscriptions\":\"https://a...content-available-to-author-only...h.tv/kraken/channels/zetaspartan21/subscriptions\"\n"
  30. + "\"editors\":\"https://a...content-available-to-author-only...h.tv/kraken/channels/zetaspartan21/editors\"\n"
  31. + "\"commercial\":\"https://a...content-available-to-author-only...h.tv/kraken/channels/zetaspartan21/commercial\"\n"
  32. + "\"teams\":\"https://a...content-available-to-author-only...h.tv/kraken/channels/zetaspartan21/teams\"\n"
  33. + "\"features\":\"https://a...content-available-to-author-only...h.tv/kraken/channels/zetaspartan21/features\"\n"
  34. + "\"videos\":\"https://a...content-available-to-author-only...h.tv/kraken/channels/zetaspartan21/videos\"\n"
  35. + "\"self\":\"https://a...content-available-to-author-only...h.tv/kraken/channels/zetaspartan21\"\n"
  36. + "\"follows\":\"https://a...content-available-to-author-only...h.tv/kraken/channels/zetaspartan21/follows\"\n"
  37. + "\"chat\":\"https://a...content-available-to-author-only...h.tv/kraken/chat/zetaspartan21\"\n"
  38. + "\"stream_key\":\"https://a...content-available-to-author-only...h.tv/kraken/channels/zetaspartan21/stream_key\"}\n"
  39. + "\"name\":\"zetaspartan21\"\n"
  40. + "\"delay\":0\n"
  41. + "\"display_name\":\"ZetaSpartan21\"\n"
  42. + "\"video_banner\":\"http://s...content-available-to-author-only...w.net/jtv_user_pictures/zetaspartan21-channel_offline_image-b20322d22543539a-640x360.jpeg\"\n"
  43. + "\"background\":\"http://s...content-available-to-author-only...w.net/jtv_user_pictures/zetaspartan21-channel_background_image-587bde3d4f90b293.jpeg\"\n"
  44. + "\"mature\":true}\n";
  45. HashMap<String, String> map = parseEasyJson(json);
  46. Set<Entry<String, String>> entrySet = map.entrySet();
  47. for (Iterator<Entry<String, String>> iterator = entrySet.iterator(); iterator
  48. .hasNext();) {
  49. Entry<String, String> entry = (Entry<String, String>) iterator
  50. .next();
  51. System.out.printf("%-15s:%s%n", entry.getKey(), entry.getValue());
  52. }
  53. }
  54. }
Success #stdin #stdout 0.08s 380544KB
stdin
Standard input is empty
stdout
"name"         :"zetaspartan21"
"background"   :"http://s...content-available-to-author-only...w.net/jtv_user_pictures/zetaspartan21-channel_background_image-587bde3d4f90b293.jpeg"
"game"         :"Call of Duty: Black Ops II"
"_links"       :{"subscriptions":"https://a...content-available-to-author-only...h.tv/kraken/channels/zetaspartan21/subscriptions""editors":"https://a...content-available-to-author-only...h.tv/kraken/channels/zetaspartan21/editors""commercial":"https://a...content-available-to-author-only...h.tv/kraken/channels/zetaspartan21/commercial""teams":"https://a...content-available-to-author-only...h.tv/kraken/channels/zetaspartan21/teams""features":"https://a...content-available-to-author-only...h.tv/kraken/channels/zetaspartan21/features""videos":"https://a...content-available-to-author-only...h.tv/kraken/channels/zetaspartan21/videos""self":"https://a...content-available-to-author-only...h.tv/kraken/channels/zetaspartan21""follows":"https://a...content-available-to-author-only...h.tv/kraken/channels/zetaspartan21/follows""chat":"https://a...content-available-to-author-only...h.tv/kraken/chat/zetaspartan21""stream_key":"https://a...content-available-to-author-only...h.tv/kraken/channels/zetaspartan21/stream_key"}
"display_name" :"ZetaSpartan21"
"created_at"   :"2011-06-28T07:50:25Z"
"updated_at"   :"2013-05-24T11:00:26Z"
"mature"       :true
"video_banner" :"http://s...content-available-to-author-only...w.net/jtv_user_pictures/zetaspartan21-channel_offline_image-b20322d22543539a-640x360.jpeg"
"status"       :"HD [XBOX] Call of Duty Black Ops 2 OPEN LOBBY"
"url"          :"http://w...content-available-to-author-only...h.tv/zetaspartan21"
"_id"          :23170407
"banner"       :"http://s...content-available-to-author-only...w.net/jtv_user_pictures/zetaspartan21-channel_header_image-7c894f59f77ae0c1-640x125.png"
"logo"         :"http://s...content-available-to-author-only...w.net/jtv_user_pictures/zetaspartan21-profile_image-121d2cb317e8a91c-300x300.jpeg"
"delay"        :0