본문 바로가기
Study Note/Java

Java #JSONArray 와 JSONObject로 JSON 생성하기

by 시뮝 2020. 1. 14.
728x90
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

...

JSONArray jsonArray = new JSONArray();

JSONObject jsonObject = new JSONObject();
jsonObject.put("key1", "value1");
jsonObject.put("key2", "value1");

jsonArray.add(jsonObject);

String jsonString = jsonArray.toJSONString();

//jsonString
//=> [{"key1":"value1"}, {"key2":"value2"}]

 

728x90

댓글