22
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

posted at

updated at

Unity C# JSONObjectを使って簡単なJSON文字列をパースする

配布元

上記URLでダウンロードしたフォルダを
Assets/Plugins 以下に配置する。

using UnityEngine;

public class Sample : MonoBehaviour {

    string msg = "{\"hoge\":\"DUMMY\",\"foo\":123,\"moge\":true}";

    void Start () {

        JSONObject json = new JSONObject(msg);

        string hoge = json.GetField("hoge").str;
        float foo = json.GetField("foo").n;
        bool moge = json.GetField("moge").b;

        Debug.Log(hoge); // DUMMY
        Debug.Log(foo); // 123
        Debug.Log(moge); // true
    }
}

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Sign upLogin
22
Help us understand the problem. What are the problem?