samedi 15 novembre 2014

java how to iterate through json object to get keys AND values


Vote count:

0




I'M searching for a solution to a problem, that, from my understanding, should be fairly common.


I have a bunch of json objects with different keys (some represent a user, some a text by the user, some a place). Now what I need to do is, create a dataset in my key-value store db (happens to be an embedded neo4j) for every json object to come in - I need to use the java interface not the rest interface.


The problem is, I do not know the json layout (names of keys) during compile time - well of course I do know them for each object type, but I don't want to write a bunch of methods for each and every object type but rather a generic method. So I thought, well, no big deal, I just create an entry with the key being the json-key and the value being the json-value.


BUT, I can't, for the sake of whatever, find a solution to iterate over a json structure and retrieve the key-names. Every solution I found so far, expects the keynames to be known in advance to get the value.


Is there any way of doing so??? Is this such a rare situation? I would have expected this to be quite a common a task.


Can anyone help??? Thanks in advance,


Chris



asked 46 secs ago







java how to iterate through json object to get keys AND values

Aucun commentaire:

Enregistrer un commentaire