List<String> 使用fastjson转换为json字符串
时间: 2024-04-12 22:31:37 浏览: 200
Sure! Here's an example of converting a List of Strings to a JSON string using FastJSON in Java:
```java
import com.alibaba.fastjson.JSON;
public class Main {
public static void main(String[] args) {
List<String> stringList = new ArrayList<>();
stringList.add("string1");
stringList.add("string2");
stringList.add("string3");
// Convert List to JSON string
String jsonString = JSON.toJSONString(stringList);
System.out.println(jsonString);
}
}
```
In this example, we first create a List of Strings called `stringList` and add some strings to it. Then, we use the `JSON.toJSONString()` method from FastJSON to convert the List to a JSON string. Finally, we print the JSON string.
Make sure 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).
阅读全文
相关推荐
















