开发者

How to remove field values from java to gson().tojson

开发者 https://www.devze.com 2023-02-13 09:24 出处:网络
my json output displays field name in my json array. [name:jimmy,surname:hat] what do i need to do to return in this format with just the values开发者_C百科.

my json output displays field name in my json array.

[name:jimmy,surname:hat]

what do i need to do to return in this format with just the values开发者_C百科.

[jimmy,hat]


Typically if you have an array in your code, something like this:

class X {
    String[] y = new String[] { "a", "b", "c" }
}

Gson converts to:

{
    "y":["a","b","c"]
} 

If your array is holding objects, i.e.

class Y {
    String name;
    String val;
}
class X {
    Y[] y; // some data
}

Gson converts to:

{
    "y":[{"name":"n1","val":"v1"},{"name":"n2","val":"v2"}]
}

So, if you want your array to be only values, just be sure it's an array of strings.

0

精彩评论

暂无评论...
验证码 换一张
取 消