"If you do nothing, nothing will happen."

프로그래밍

[Unity3D] JSONObject 다운로드 & 사용법

tedhong 2023. 2. 9. 14:13
2014-02-27 글쓴이 TED HONG

[Unity3D] JSONObject 다운로드 & 사용법

이전 포스팅에서 언급한 더 간단한 Json 라이브러리인 JSONObject 사용법에 대해 알아보자.

우선 다운로드는 에셋스토어에서 Json Object 로 검색해 설치해도 되고
JSONObject wiki (http://wiki.unity3d.com/index.php/JSONObject#Download) 에서 다운로드 받을 수 있다.

다운 받아 압축풀고 Assets 폴더에 넣으면 설치는 끝.

문법

 

//1. Json string 을 JsonObject 로 변환
        JSONObject obj = new JSONObject(response.Text);
//2.JsonObject 를 Dictionary 로 변환
        Dictionary<string, string> dic = obj.ToDictionary();

// 3.빈 JsonObject 생성
        JSONObject j = new JSONObject(JSONObject.Type.OBJECT);
//4.항목추가
        j.AddField("field1", "sampletext");
//5.array 만들기
        JSONObject arr = new JSONObject(JSONObject.Type.ARRAY);
        j.AddField("field2", arr);
        arr.Add(1);
        arr.Add(2);
        arr.Add(3);
//6.항목 삭제
        j.RemoveField("field1");
//7.JsonObject 을 Json 문자열로 변환
        string encodedString = j.Print();

 

끝.

 

더 간단하다.

 

간단해서 마음에 든다  ㅎㅎ;;