Json 사용하기1




1. Create Object and Seting
오브젝트를 생성하고 설정한다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// UI 사용
using UnityEngine.UI;
// MiniJson 사용
using GameData;
public class TestDictionary : MonoBehaviour
{
    // 기본 텍스트 파일 - Json파일
    public TextAsset _text;
    // Key & Value
    Dictionary<stringobject> dictionarytest1;
    void Start()
    {
        // dictionary file - All information load 
        dictionarytest1 = MiniJSON.jsonDecode(_text.text) 
        as Dictionary<stringobject>;
    }
    public void Serch(InputField ip)
    {
        // Dictiona file - a information load
        Dictionary<stringobject> dictionarytest2;
        Debug.Log("검색할 이름은 " + ip.text + "입니다.");
        // if(ip.text check)  
        if (dictionarytest1.ContainsKey(ip.text.Trim()))
        {
            dictionarytest2 = dictionarytest1[ip.text.Trim()] 
        as Dictionary<stringobject>;
            ShowData(dictionarytest2);
        }
        // dissapear InputField text
        ip.text = "";
    }
    public Text _nameIp;
    public Text _ageIp;
    void ShowData(Dictionary<stringobject> infoDic)
    {
        // output name
        _nameIp.text = infoDic["name"].ToString();
        // output age
        _ageIp.text = infoDic["age"].ToString();
    }
}
cs

2. C#Script, Json 작성 
MiniJson Script 추가
MiniJson은 이곳에서 다운받을수 있다.
Download here
http://techblog.procurios.nl/k/618/news/view/14605/14863/How-do-I-write-my-own-parser-for-JSON.html

 
3. Empty Object - Add C#Script

4. InputField_On End Edit setting



6. check

끝.



댓글