package thirdparty.json;

import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class JSONObjectTest {
	@SuppressWarnings("unused")
	private static final Logger logger = LoggerFactory.getLogger(JSONObjectTest.class);
	
	@Test
	public void test() {
		// 단일 객체
		JSONObject ob = new JSONObject();
		ob.put("이름1", "값1");
		ob.put("이름2", "값2");
		
		Assert.assertEquals("{\"이름2\":\"값2\",\"이름1\":\"값1\"}", ob.toString());

		// 객체 배열
		JSONArray list = new JSONArray();

		JSONObject ob2 = new JSONObject();
		ob2.put("이름1", "값1");
		ob2.put("이름2", "값2");
		list.put(ob2);

		ob2 = new JSONObject();
		ob2.put("이름1", "값1");
		ob2.put("이름2", "값2");
		list.put(ob2);
		
		Assert.assertEquals("[{\"이름2\":\"값2\",\"이름1\":\"값1\"},{\"이름2\":\"값2\",\"이름1\":\"값1\"}]", list.toString());
	}
}

@@ -882,10 +882,666 @@
 ());%0A%09%7D%0A
+%09%0A%09@Test%0A%09public void parseFromString() %7B%0A%09%09final String jsonString = %22%7B%5C%22status%5C%22:%5C%220000%5C%22,%5C%22data%5C%22:%5B%5B1582464360000,%5C%22321000%5C%22,%5C%22320900%5C%22,%5C%22321000%5C%22,%5C%22320900%5C%22,%5C%2211.7071%5C%22%5D,%5B%5D,%5B%5D%5D%7D%22;%0A%09%09JSONObject object = new JSONObject(jsonString);%0A%0A%09%09JSONArray data = (JSONArray) object.get(%22data%22);%0A%09%09Assert.assertEquals(JSONArray.class, data.get(0).getClass());%0A%0A%09%09JSONArray firstElement = (JSONArray) data.get(0);%0A%09%09Assert.assertEquals(Long.class, firstElement.get(0).getClass());%0A%09%09Assert.assertEquals(String.class, firstElement.get(1).getClass());%0A%0A%09%09JSONArray secondEmptyElement = (JSONArray) data.get(1);%0A%09%09Assert.assertEquals(0, secondEmptyElement.length());%0A%09%7D%0A
 %7D%0A

add test case