简体   繁体   English

将字符串转换为2D数组(Java)

[英]Convert string to 2d array (java)

I am trying to convert string like this: 我正在尝试像这样转换字符串:

{"Shops":[
{"city":"Riga","shops":[{"a":"some info here","b":"...","c":"..."},{"a":"some info here","b":"...","c":"..."}]},{"city":"Liepaja","shops":[{"a":"info here","b":"info....","c":"..."}]
]}

to 2d array, like 到二维数组,像

shops[0][0]=>{"a":"some info here","b":"...","c":"..."}
shops[1][0]=>{"a":"info here","b":"info....","c":"..."}

Is it possible? 可能吗? Is there some easy way to do that? 有一些简单的方法可以做到吗?

I've searched, tried, but I still don't know how to do that. 我已经搜索,尝试过,但是我仍然不知道该怎么做。 I'm new in java. 我是Java新手。

That looks like JSON data, and you should treat it as such. 看起来像JSON数据,您应该这样处理。

Try a JSON parsing library for Java. 尝试使用Java的JSON解析库。 I like GSON for its simplicity. 我喜欢GSON的简单性。 Take a look at the Gson.fromJson() set of methods. 看一下Gson.fromJson()方法集。

That is a JSON string. 那是一个JSON字符串。 There are a number of libraries that will do this for you. 有许多库可以为您完成此操作。

The type of data you have posted is JSON encoded. 您发布的数据类型是JSON编码。 you could use a json encoder and decoder to do this job easily. 您可以使用json编码器和解码器轻松完成此工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM