可以使用 JSONObject 的构造方法将 String 类型的 JSON 字符串转换为 JSONObject 类型。

示例代码如下:

import org.json.JSONObject;

public class Main {
    public static void main(String[] args) {
        String jsonString = '{"name":"John", "age":30, "city":"New York"}';
        JSONObject jsonObject = new JSONObject(jsonString);
        System.out.println(jsonObject);
    }
}

输出结果:

{"name":"John","age":30,"city":"New York"}
Java String 转 JSONObject:使用 JSONObject 构造方法