java - JSONSmart parsing a whole array and getting each object? -


an example json.

edit: i've put on pastebin because of how big file - http://pastebin.com/wdr2pabp

how array of "objects", iterate through , name (i.e. "minecraft/sounds/dig/sand4.ogg") , hash each of these files?

my attempts:

filereader fr = new filereader(location.getabsolutepath()); jsonarray iindexes = (jsonarray) parser.parse(fr); 
  • i've tried making objects jsonobject making jsonarray using loop every object, npe or classcast exception (for atttempt before one).

what have there json object, not json array. conceptually, can treat set of name/value pairs, according json specification, nv pairs not ordered; i.e. set, not list.

there no standard way turn jsonobject jsonarray. casting won't work, , jsonobject doesn't have method conversion. , certainly, there no way using jsonsmart preserve apparent order of nv pairs in source file / string. (which thing, imo, because order shouldn't mean anything.)

if want iterate nv pairs, best way use entryset method jsonobject's entries set ... , iterate set. (the jsonsmart version of jsonobject subclass of hashmap.)


now if set of entries in "objects" supposed ordered, have designed json scheme incorrectly. should using json array (using [...] json syntax) , elements need restructured objects; e.g.

  [ {       "name": "realms/lang/de_de.lang",       "hash": "10a54fc66c8f479bb65c8d39c3b62265ac82e742",       "size": 8112     },     {       "name": "realms/lang/cy_gb.lang",       "hash": "14cfb2f24e7d91dbc22a2a0e3b880d9829320243",       "size": 7347     },     etcetera   ] 

when parse using jsonsmart jsonarray.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -