JSONArray.parseArray
时间: 2024-05-04 13:15:26 浏览: 86
JSONArray解析包
JSONArray.parseArray() is a method in the Java programming language that belongs to the com.alibaba.fastjson.JSONArray class. This method is used to parse a JSON string into a JSONArray object.
The syntax for JSONArray.parseArray() is:
```java
public static JSONArray parseArray(String text)
```
The method takes a JSON formatted string as input and returns a JSONArray object that represents the parsed JSON. The method throws a JSONParseException if the input string is not a valid JSON string.
Example:
```java
import com.alibaba.fastjson.JSONArray;
public class Main {
public static void main(String[] args) {
String jsonString = "[{\"name\":\"John\", \"age\":30}, {\"name\":\"Jane\", \"age\":25}]";
JSONArray jsonArray = JSONArray.parseArray(jsonString);
System.out.println(jsonArray);
}
}
```
In the example above, we have a JSON formatted string that contains an array of two objects. We use the JSONArray.parseArray() method to parse the JSON string and store the result in a JSONArray object. Finally, we print the JSONArray object to the console.
Output:
```
[{"name":"John","age":30},{"name":"Jane","age":25}]
```
阅读全文