{"id":1179,"date":"2017-07-07T10:15:10","date_gmt":"2017-07-07T02:15:10","guid":{"rendered":"http:\/\/39.100.100.179\/?p=1179"},"modified":"2017-07-26T20:53:52","modified_gmt":"2017-07-26T12:53:52","slug":"jsonfx%e5%ba%8f%e5%88%97%e5%8c%96%e4%b9%8b%e5%bf%bd%e7%95%a5null%e5%80%bc","status":"publish","type":"post","link":"http:\/\/www.u3d8.com\/?p=1179","title":{"rendered":"JsonFx\u5e8f\u5217\u5316\u4e4b\u5ffd\u7565null\u503c"},"content":{"rendered":"<p>\u6211\u4f7f\u7528\u7684JsonFX\u8fdb\u884cjson\u7684\u5e8f\u5217\u5316\u64cd\u4f5c\u3002\u5bf9JsonFX\u7684\u4fdd\u5b58\u4e0e\u8bfb\u53d6\uff0c\u7f51\u4e0a\u7684\u6559\u7a0b\u4e00\u6293\u4e00\u5927\u628a\uff0c\u8fd9\u91cc\u5c31\u4e0d\u518d\u8d58\u8ff0\u4e86\u3002<\/p>\n<p>\u4eca\u5929\u4e3b\u8981\u5b9e\u73b0\u7684\u662f\u5982\u4f55\u5728\u5e8f\u5217\u5316\u7684\u65f6\u5019\uff0c\u5ffd\u7565\u7a7a\u503c\uff0c\u4ece\u800c\u51cf\u5c11json\u6587\u4ef6\u7684\u7a7a\u95f4\u5360\u7528\u3002<\/p>\n<pre class=\"lang:c# decode:true \">using UnityEngine;\r\nusing System.Collections;\r\nusing System.Collections.Generic;\r\nusing JsonFx.Json;    \/\/ \u5f15\u5165\u5e93\r\nusing System.ComponentModel;\r\n\r\npublic class NewBehaviourScript : MonoBehaviour\r\n{\r\n\r\n    \/\/ Use this for initialization\r\n    void Start()\r\n    {\r\n\r\n        Bag bag1 = new Bag();\r\n        bag1.id = 1;\r\n        bag1.name = \"\u6b66\u5668\";\r\n        bag1.equipments = new List&lt;Equipment&gt;();\r\n        Equipment equipment = new Equipment();\r\n        equipment.type = 11;\r\n        bag1.equipments.Add(equipment);\r\n        \/\/ \u8fd9\u91cc\u6211\u4eec\u6ca1\u6709\u7ed9weapons\u5bf9\u8c61\u8d4b\u503c\r\n\r\n        string data = JsonWriter.Serialize(bag1);     \/\/ \u5c06\u5bf9\u8c61\u8f6c\u6210json\r\n\r\n        Debug.Log(data);     \/\/ \u770b\u4e0b\u6211\u4eec\u4fdd\u5b58\u7684json\u662f\u5426\u5305\u542bweapons\r\n    }\r\n}\r\n\r\n\r\npublic class Bag\r\n{\r\n\r\n    public int id;\r\n    public string name;\r\n\r\n    [JsonSpecifiedProperty(\"EquipmentsNotNull\")]     \/\/ \u5982\u679c\u8be5\u503c\u4e3anull \u5219\u4e0d\u5e8f\u5217\u5316\r\n    public List&lt;Equipment&gt; equipments;\r\n\r\n    [JsonIgnore]            \/\/ \u4e0d\u7ba1\u8be5\u503c\u662f\u5426\u4e3anull \u90fd\u4e0d\u4f1a\u53c2\u4e0e\u5e8f\u5217\u5316\r\n    public bool EquipmentsNotNull { get { return equipments != null; } }\r\n\r\n    \/\/ \u5982\u679c\u8be5\u503c\u4e3anull\u65f6\uff0c\u60f3\u88abjson\u5e8f\u5217\u5316\u5ffd\u7565\uff0c\u53ef\u4ee5\u7528\u4ee5\u4e0b\u4e24\u79cd\u65b9\u5f0f\r\n    \/\/ \u7b2c\u4e00\u79cd DefaultValue\r\n    [DefaultValue(null)]\r\n    public List&lt;Weapon&gt; weapons;\r\n\r\n    \/\/ \u7b2c\u4e8c\u79cd JsonSpecifiedProperty \u914d\u5408 JsonIgnore\u4f7f\u7528\r\n    \/\/[JsonSpecifiedProperty(\"WeaponsNotNull\")]    \r\n    \/\/public List&lt;Weapon&gt; weapons;\r\n\r\n    \/\/[JsonIgnore]\r\n    \/\/public bool WeaponsNotNull { get { return weapons != null; } }\r\n}\r\n\r\npublic class Equipment\r\n{\r\n    public int type;\r\n}\r\n\r\npublic class Weapon\r\n{\r\n    public int damage;\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p>\u8f93\u51fa\u7ed3\u679c\uff1a<a href=\"http:\/\/www.u3d8.com\/wp-content\/uploads\/2017\/07\/QQ\u622a\u56fe20170707101357.png\" data-lightbox=\"image_lg\"><img title=\"JsonFx\u5e8f\u5217\u5316\u4e4b\u5ffd\u7565null\u503c - \u7b2c1\u5f20  | u3d8\u6280\u672f\u5206\u4eab\" alt=\"JsonFx\u5e8f\u5217\u5316\u4e4b\u5ffd\u7565null\u503c - \u7b2c1\u5f20  | u3d8\u6280\u672f\u5206\u4eab\"  loading=\"lazy\" class=\"aligncenter size-full wp-image-1181\"  data-src=\"http:\/\/www.u3d8.com\/wp-content\/uploads\/2017\/07\/QQ\u622a\u56fe20170707101357.png\" width=\"421\" height=\"77\" srcset=\"http:\/\/www.u3d8.com\/wp-content\/uploads\/2017\/07\/QQ\u622a\u56fe20170707101357.png 421w, http:\/\/www.u3d8.com\/wp-content\/uploads\/2017\/07\/QQ\u622a\u56fe20170707101357-300x55.png 300w\" sizes=\"(max-width: 421px) 100vw, 421px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6211\u4f7f\u7528\u7684JsonFX\u8fdb\u884cjson\u7684\u5e8f\u5217\u5316\u64cd\u4f5c\u3002\u5bf9JsonFX\u7684\u4fdd\u5b58\u4e0e\u8bfb\u53d6\uff0c\u7f51\u4e0a\u7684 &hellip; <a href=\"http:\/\/www.u3d8.com\/?p=1179\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[24],"tags":[267,265,266],"_links":{"self":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/1179"}],"collection":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1179"}],"version-history":[{"count":6,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/1179\/revisions"}],"predecessor-version":[{"id":1186,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/1179\/revisions\/1186"}],"wp:attachment":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1179"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1179"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1179"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}