!636 !standard functions !include #728 // JsonTok main { psvm { String id = args.length == 0 ? "#681" : args[0]; String[] x = loadSnippetAndTitle(id); System.out.println(x[0]); System.out.println(x[1]); } // for now, no caching... static String[] loadSnippetAndTitle(String id) throws IOException { boolean debug = true; long snippetID = parseSnippetID(id); String json; try { URL url = new URL("http://tinybrain.de:8080/tb-int/get.php?id=" + snippetID + "&full=1"); json = loadPage(url); } catch (FileNotFoundException e) { throw new IOException("Snippet #" + snippetID + " not found or not public"); } if (debug) System.out.println("JSON [[" + json + "]]"); Map<String, String> map = parseJsonObject(json); return new String[] {map.get("text"), map.get("title")}; } static Map<String, String> parseJsonObject(String s) { List<String> tok = JsonTok.split(s); new (Tree)Map<String, String> map; for (int i = 1; i+4 < tok.size(); i += 2) { if (tok.get(i+2).equals(":")) map.put(unquote(tok.get(i)), unquote(tok.get(i+4))); } return map; } }
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1000534 |
| Snippet name: | test loadSnippetAndTitle (developer platform) |
| Eternal ID of this version: | #1000534/1 |
| Text MD5: | 0d3fa26896ccefc18ba43ecfc0ed7246 |
| Author: | stefan |
| Category: | |
| Type: | JavaX source code |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2015-08-10 23:58:40 |
| Source code size: | 1218 bytes / 42 lines |
| Pitched / IR pitched: | No / Yes |
| Views / Downloads: | 858 / 802 |
| Referenced in: | #3000382 - Answer for ferdie (>> t = 1, f = 0) #3000383 - Answer for funkoverflow (>> t=1, f=0 okay) |