可以使用JSON库将JSON字符串数组转换为对象。

例如,使用Jackson库:

import com.fasterxml.jackson.databind.ObjectMapper;

String json = "[{\"name\":\"John\",\"age\":30},{\"name\":\"Jane\",\"age\":25}]";

ObjectMapper mapper = new ObjectMapper();
Person[] persons = mapper.readValue(json, Person[].class);

这里的Person是一个自定义的Java类,用来表示JSON中的对象:

public class Person {
    private String name;
    private int age;

    // getters and setters
}

在这个例子中,readValue方法将JSON字符串数组转换为Person对象的数组。

javajson字符串数组转对象

原文地址: http://www.cveoy.top/t/topic/bq6c 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录