LevelUp! Studio » Unity C# https://blog.levelup.in.th Experience the new world. Fri, 26 May 2017 10:06:07 +0000 th hourly 1 http://wordpress.org/?v=3.8.1 [Unity C# SimpleJSON] วิธีการประกาศตัวแปร JSONClass แบบ inline https://blog.levelup.in.th/2014/12/31/unity-c-sharp-simplejson-how-to-set-jsonclass-value-inline/ https://blog.levelup.in.th/2014/12/31/unity-c-sharp-simplejson-how-to-set-jsonclass-value-inline/#comments Wed, 31 Dec 2014 14:25:33 +0000 http://blog.levelup.in.th/?p=3990 วันนี้จะมาพูดถึงวิธีการประกาศตัวแปร JSONClass แบบ inline ที่ดูจะทำง๊ายง่ายแต่หา Syntax ที่ถูกกันไม่ได้อยู่นาน ซึ่งโดยปกติแล้วเราจะประกาศตัวแปรก่อนแล้วตามด้วย .Add เพื่อเพิ่มข้อมูลเข้าไปที่ละก้อน ดังนี้


JSONClass SampleObject = new JSONClass();
SampleObject.Add("action", "attack");
SampleObject.Add("target", targetPosition.ToString());
SampleObject.Add("order", DragableUnits.SkillOrderLabel.text);

แต่ถ้าเราอยากทำเป็น InLine ก็เขียนได้ง่ายๆแค่นี้ครับ


JSONClass SampleObject = new JSONClass();
{
{"action", "attack"},
{"target", targetPosition.ToString()},
{"order", DragableUnits.SkillOrderLabel.text},
};

ง่ายๆแค่นี้แหละครับผม

]]>
https://blog.levelup.in.th/2014/12/31/unity-c-sharp-simplejson-how-to-set-jsonclass-value-inline/feed/ 0