当前位置: 首页>>代码示例>>C#>>正文


C# JSONObject.Clear方法代码示例

本文整理汇总了C#中JSONObject.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# JSONObject.Clear方法的具体用法?C# JSONObject.Clear怎么用?C# JSONObject.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JSONObject的用法示例。


在下文中一共展示了JSONObject.Clear方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Start

    void Start()
    {
        infoText.gameObject.SetActive(false);

        //JSONObject usage example:

        //Parse string into a JSONObject:
        JSONObject.Parse(stringToEvaluate);

        //You can also create an "empty" JSONObject
        JSONObject emptyObject = new JSONObject();

        //Adding values is easy (values are implicitly converted to JSONValues):
        emptyObject.Add("key", "value");
        emptyObject.Add("otherKey", 123);
        emptyObject.Add("thirdKey", false);
        emptyObject.Add("fourthKey", new JSONValue(JSONValueType.Null));

        //You can iterate through all values with a simple for-each loop
        foreach (KeyValuePair<string, JSONValue> pair in emptyObject) {
            Debug.Log("key : value -> " + pair.Key + " : " + pair.Value);

            //Each JSONValue has a JSONValueType that tells you what type of value it is. Valid values are: String, Number, Object, Array, Boolean or Null.
            Debug.Log("pair.Value.Type.ToString() -> " + pair.Value.Type.ToString());

            if (pair.Value.Type == JSONValueType.Number) {
                //You can access values with the properties Str, Number, Obj, Array and Boolean
                Debug.Log("Value is a number: " + pair.Value.Number);
            }
        }

        //JSONObject's can also be created using this syntax:
        JSONObject newObject = new JSONObject {{"key", "value"}, {"otherKey", 123}, {"thirdKey", false}};

        //JSONObject overrides ToString() and outputs valid JSON
        Debug.Log("newObject.ToString() -> " + newObject.ToString());

        //JSONObjects support array accessors
        Debug.Log("newObject[\"key\"].Str -> " + newObject["key"].Str);

        //It also has a method to do the same
        Debug.Log("newObject.GetValue(\"otherKey\").ToString() -> " + newObject.GetValue("otherKey").ToString());

        //As well as a method to determine whether a key exists or not
        Debug.Log("newObject.ContainsKey(\"NotAKey\") -> " + newObject.ContainsKey("NotAKey"));

        //Elements can removed with Remove() and the whole object emptied with Clear()
        newObject.Remove("key");
        Debug.Log("newObject with \"key\" removed: " + newObject.ToString());

        newObject.Clear();
        Debug.Log("newObject cleared: " + newObject.ToString());
    }
开发者ID:rodrigod89,项目名称:project-decubed-online,代码行数:53,代码来源:JSONObjectTester.cs


注:本文中的JSONObject.Clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。