Java 8 JSONObject to JSONString Conversion: A Simple Guide
"Java 8 JSONObject to JSONString Conversion: A Simple Guide"\n\nIn Java 8, you can use the JSONObject class from the org.json library to convert a JSONObject to a JSONString. Here's a simple example:\n\njava\nimport org.json.JSONObject;\n\npublic class Main {\n public static void main(String[] args) {\n // Create a JSONObject object\n JSONObject jsonObject = new JSONObject();\n jsonObject.put("name", "John");\n jsonObject.put("age", 30);\n jsonObject.put("city", "New York");\n\n // Convert JSONObject to JSONString\n String jsonString = jsonObject.toString();\n\n // Print JSONString\n System.out.println(jsonString);\n }\n}\n\n\nOutput:\n\n\n{"name":"John","age":30,"city":"New York"}\n\n\nHere, we used the toString() method of JSONObject to convert it into a JSONString.
原文地址: https://www.cveoy.top/t/topic/qjBs 著作权归作者所有。请勿转载和采集!