JSon 파일을 다음 형식으로 표시하려고합니다. 하지만 내 프로그램을 실행할 때 맨 아래쪽에 윗부분이 표시됩니다. 왜 이런거야? 이 일을 제대로하고 있습니까? 코드의 출력과 예상 출력을 찾으십시오.Json 형식이 잘못 표시되었습니다.
코드 :
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);
}
}
출력 :
예상 출력 :
고마워요! 그것을 밖으로 시도 할 것이다 –