Hi,
I do have a com.fasterxml.jackson.databind.JsonNode
format like this :
{ "jcr:primaryType": "nt:unstructured", "sling:resourceType": "foundation/components/parsys", "rwdcarousel": { "jcr:primaryType": "nt:unstructured", "jcr:createdBy": "admin", "contentFinderImage": "/etc/designs/webcms-ngtv/globallibs/img/rwdCarouselModuleIcon.jpg", "rwdcarouselType": "singleCarousel", "jcr:lastModifiedBy": "admin" } }
Out of this, I need to fetch keys which contains values inside { }. Like, in this case, rwdcarousel.
Solved! Go to Solution.
Views
Replies
Total Likes
1. Put the complete json in JSONObject x = new JSONObject(your_json).
2. Execute x.getJSONObject("social");
Take a look @ http://crunchify.com/java-how-to-parse-jsonobject-and-jsonarrays/
Views
Replies
Total Likes
1. Put the complete json in JSONObject x = new JSONObject(your_json).
2. Execute x.getJSONObject("social");
Take a look @ http://crunchify.com/java-how-to-parse-jsonobject-and-jsonarrays/
Views
Replies
Total Likes
Hi
Please have a look at these post to get answer to your question:
1. JavaScript
// Link:- http://stackoverflow.com/questions/18080543/how-to-extract-keys-from-key-value-json-object
Let say, your Json is:
{"16": {
"events": {
"burstevents": {
"1369353600000.0": "maj", "1371600000000.0": "maj", "1373414400000.0": "maj", "1373500800000.0": "maj", "1373673600000.0": "maj"
},
"sentevents": {
"1370736000000.0": "pos", "1370822400000.0": "pos", "1370908800000.0": "pos"
}
}
}
}
You can iterate over the keys using the in keyword.
var json = $.parseJSON(data);
var keys = array();
for(var key in json[16].events.burstevents)
{
keys.push(key);
}
You can do it with jQuery
var json = $.parseJSON(data);
var keys = $.map(json[16].events.burstevents,function(v,k) { return k; });
You can use JavaScript Object
var json = $.parseJSON(data);
var keys = Object.keys(json[16].events.burstevents);
2. Java
//Link:- http://stackoverflow.com/questions/4407532/parse-json-object-with-string-and-value-only
String s = "{menu:{\"1\":\"sql\", \"2\":\"android\", \"3\":\"mvc\"}}";
JSONObject jObject = new JSONObject(s);
JSONObject menu = jObject.getJSONObject("menu");
Map<String,String> map = new HashMap<String,String>();
Iterator iter = menu.keys();
while(iter.hasNext()){
String key = (String)iter.next();
String value = menu.getString(key);
map.put(key,value);
}
Thanks and Regards
Kautuk Sahni
Views
Replies
Total Likes
Views
Likes
Replies