
JSONObject是java.util.HashMap的子类,其中不提供顺序。我们还可以在 JSONValue.toJSONString(map) 方法的帮助下使用元素的严格排序,即通过 java.util.LinkedHashMap 的实现。 p>
我们可以在下面的两个示例中对 JSON 对象进行编码。
本文档主要讲述的是j2me3D游戏开发简单教程; 如今,3D图形几乎是任何一部游戏的关键部分,甚至一些应用程序也通过用3D形式来描述信息而获得了成功。如前文中所述,以立即模式和手工编码建立所有的3D对象的方式进行开发速度很慢且很复杂。应用程序中多边形的所有角点必须在数组中独立编码。在JSR 184中,这称为立即模式。希望本文档会给有需要的朋友带来帮助;感兴趣的朋友可以过来看看
0
import java.util.*;
import org.json.simple.JSONObject;
public class JSONEncodingTest {
public static void main(String[] args) {
Map<Object, Object> dataMap = new HashMap<Object, Object>();
dataMap.put("Name", "Adithya");
dataMap.put("Age", new Integer(25));
dataMap.put("Salary", new Double(25000.00));
dataMap.put("Employee Id", new Integer(115));
dataMap.put("Company", "TutorialsPoint");
JSONObject jsonObj = new JSONObject(dataMap);
System.out.print("Encoding a JSON object: ");
System.out.print(jsonObj);
}
}Encoding a JSON object: {"Salary":25000.0,"Employee id":115,"Company":"TutorialsPoint","Age":25,"Name":"Adithya"}import java.io.*;
import org.json.simple.*;
public class JSONEncodingTest1 {
public static void main(String[] args) throws IOException {
JSONObject obj = new JSONObject();
obj.put("Name", "Jai");
obj.put("Mobile_Number", new Integer(995998480));
obj.put("Bank_Balance", new Double(50000.00));
obj.put("Is_A_SelfEmployee", new Boolean(false));
StringWriter out = new StringWriter();
obj.writeJSONString(out);
String jsonText = out.toString();
System.out.print(jsonText);
}
}{"Is_A_SelfEmployee":false,"Bank_Balance":50000.0,"Mobile_Number":995998480,"Name":"Jai"}以上就是我们如何在Java中对JSON对象进行编码?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号