将json数组转换为json

将json数组转换为json

本文介绍了将json数组转换为json(原始)字符串列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些像这样的json数据:

I've some json data like this:

[{"id":"someid","name":"some name"}, {"id":"some other id", "name":"a name"}]

我想在上面的数组aslist中获取json对象,如

I want to get the json objects in the above array aslist of strings like

(每个字符串都是字符串形式的json对象,(List< String>)

(each string is json object in string form, (List<String>))

(为简单起见)

 [ {"id":"someid","name":"some name"},{"id":"some other id", "name":"a name"}

我尝试使用jackson的TypeReference>但是它导致了像id,someid这样的成分部分进入列表元素而不是制作每个json对象都是一个字符串元素。

I tried using jackson's TypeReference> but it is causing consituents parts like id, someid into the list elements instead of making each json object a string element.

我也尝试过使用jackson TypeReference>,这次我正确得到了对象的数量,但所有的双引号都没了':'转换为'=',因此它转换为java对象而不是json原始字符串。

I also tried using jackson TypeReference>, this time I'm getting the number of objects correctly, but all the double quotes are gone and ':' are converted to '=', so it converted to java object not a json raw string.

我变得像[{id = someid,name = somename},{ id =其他一些id,name = a name}]

I'm getting like [{id=someid,name=somename},{id=some other id, name=a name}]

我很想知道如何使用Jackson库这样做。

I'm interested to know how to do this using Jackson library.

任何帮助都将不胜感激。

Any help would be appreciated.

推荐答案

我能够使用json的JSONArray实现所需的结果图书馆。对于任何一个遇到这个问题我都发布这个。

I was able to achieve the desired to result using JSONArray from json library. For any one comes across this question I'm posting this.

JSONArray jsonArray = new JSONArray(jsonString);
List<String> list = new ArrayList<String());
for(int i = 0 ; i < jsonArray.length();i++){
    list.add(jsonArray.getJSONObject(i));
}

但是我仍然有兴趣知道如何使用杰克逊图书馆这样做。

However I'm still interested to know how to do this using Jackson library alone.

这篇关于将json数组转换为json(原始)字符串列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 02:20