LoginSignup
22
22

More than 5 years have passed since last update.

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

Last updated at Posted at 2014-08-06

配布元

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

22
22
0

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
  3. You can use dark theme
What you can do with signing up
22
22