java list<String>字符串转List 给一个使用fastjson转换案例
时间: 2024-04-12 14:31:35 浏览: 167
java list 转换为json数据
4星 · 用户满意度95%
Sure! Here's an example of converting a JSON string to a List of Strings using FastJSON in Java:
```java
import com.alibaba.fastjson.JSON;
public class Main {
public static void main(String[] args) {
String jsonString = "[\"string1\", \"string2\", \"string3\"]";
// Convert JSON string to List
List<String> stringList = JSON.parseArray(jsonString, String.class);
// Print the converted list
for (String str : stringList) {
System.out.println(str);
}
}
}
```
In this example, we first define a JSON string `jsonString` containing an array of strings. We then use the `JSON.parseArray()` method from FastJSON to convert the JSON string to a List of Strings. Finally, we iterate over the elements in the list and print each element.
Note that you need to include the FastJSON library in your project for this example to work. You can download the FastJSON library from the official website or include it as a dependency in your build file (e.g., Maven or Gradle).
阅读全文