LoginSignup
22

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
    }
}

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
22