Ich versuche, eine JSon-Datei im folgenden Format anzuzeigen. Aber wenn ich mein Programm starte, wird der obere Teil unten angezeigt. Warum ist das? mache ich das richtig? Hier finden Sie ein Bild der Ausgabe und der erwarteten Ausgabe unter dem Code.Json-Format falsch angezeigt
Code:
public class Student {
public static void main(String[] args) {
int a = -7;
int b = 7;
int k = 103;
int order = 109;
int px = 60;
int py = 76;
int qx = 101;
int qy = 42;
int n = 3;
int rx = 2;
int ry = 102;
int sx = 64;
int sy = 17;
JSONObject obj = new JSONObject();
obj.put("name", "JEAN-LUC PALMYRE");
obj.put("srn", "120299364");
JSONObject objEcc = new JSONObject();
objEcc.put("a",a);
objEcc.put("b",b);
objEcc.put("k",k);
objEcc.put("order",order);
obj.put("ecc", objEcc);
JSONObject objModk_add = new JSONObject();
objModk_add.put("x", px);
objModk_add.put("y", py);
obj.put("p", objModk_add);
objModk_add.put("x", qx);
objModk_add.put("y", qy);
obj.put("q", objModk_add);
objModk_add.put("x", rx);
objModk_add.put("y", ry);
obj.put("r", objModk_add);
JSONObject objModk_mul = new JSONObject();
objModk_mul.put("x", px);
objModk_mul.put("y", py);
obj.put("p", objModk_mul);
try (FileWriter file = new FileWriter("Jean-LucPalmyre_120299364_CO3326_cw1.json"))
{
file.write(obj.toJSONString());
file.flush();
} catch (IOException e) {
e.printStackTrace();
}
System.out.print(obj);
}
}
Ausgang:
Erwartete Ausgabe:
Vielen Dank! Werde es ausprobieren –