且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将Java字符串转换为JSON对象

更新时间:2023-01-15 23:41:05

您正在将StringBuilder类的实例传递给JSONObject构造函数.

You are passing into the JSONObject constructor an instance of a StringBuilder class.

这是使用JSONObject(Object)构造函数,而不是JSONObject(String)构造函数.

This is using the JSONObject(Object) constructor, not the JSONObject(String) one.

您的代码应为:

JSONObject jsonObj = new JSONObject(jsonString.toString());