kittu
kittu

Reputation: 7018

How I get only value ignoring the key

I have a json array in database. I want to get only value ignoring the key and send it to ajax call.

Json string I have while saving:

{
    "cells": 
    [
        {
            "type": "devs.TooledModel",
            "position": 
            {
                "x": 200,
                "y": 100
            },
            "size": 
            {
                "width": 71,
                "height": 100
            },
                ".": 
            {
                    "magnet": false
            }
        }
    ]
}

I want to return the exact json array from database but I am getting a key appended because I am using a map in java servlet to retrieve json:

List<Map<String, Object>> result = new ArrayList<>();

    while (rSet.next()) {
        Map<String, Object> row = new HashMap<>();
        row.put("JSON_Diagram", rSet.getString("JSON_INFO"));
        result.add(row);
    }

json received: JSON_Diagram: "cells%5B0%5D%5Btype%5D=devs.TooledModel&cells..

How do I remove the key JSON_Diagram and get only value ? Tried with Object value = result.get(0); but didn't work

Upvotes: 2

Views: 484

Answers (2)

Mihir
Mihir

Reputation: 581

You need to get a list of all the keys, loop over them and add them to your map and if you need only value add values only to list as shown in the example below:

Map<String,Object> row  = new HashMap<String,Object>();
    Iterator iter = rSet.keys();
    while(iter.hasNext()){
        String key = (String)iter.next();
        String value = rSet.getString(key);
        row.put(key,value);
        result.add(value);

    }

Upvotes: 3

Som Bhattacharyya
Som Bhattacharyya

Reputation: 4112

So once you have the map just do a a map.values.

[http://docs.oracle.com/javase/7/docs/api/java/util/Map.html#values()][1]

Then just use the resultant collection!

Upvotes: 2

Related Questions