本文整理汇总了C#中JsonObject.AddMember方法的典型用法代码示例。如果您正苦于以下问题:C# JsonObject.AddMember方法的具体用法?C# JsonObject.AddMember怎么用?C# JsonObject.AddMember使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonObject
的用法示例。
在下文中一共展示了JsonObject.AddMember方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildFromCode
public void BuildFromCode()
{
JsonObject json = new JsonObject();
json.AddMember("member1", "INIT");
json.AddMember("member2","foobar");
json.AddMember("member3");
JsonValue jv = json.GetValue ("member3");
jv.SetArray();
jv.array.PushBack(1);
jv.array.PushBack(2);
jv.array.PushBack(3);
jv.array.PushBack(4);
JsonObject jsonObj = new JsonObject();
jsonObj.AddMember("intv", 123);
jsonObj.AddMember("srtv", "hoge");
jsonObj.AddMember("doublev", 123.456);
json.AddMember("member4", jsonObj);
Debug.Log (json.ToPrettyString ());
}
示例2: CastToWringType
public void CastToWringType()
{
JsonObject json = new JsonObject();
json.AddMember("member1");
json["member1"].stringValue = "hello world";
Assert.Catch ( typeof(InvalidCastException), delegate { int v = (int)json["member1"]; } );
}
示例3: CastToString
public void CastToString()
{
JsonObject json = new JsonObject();
json.AddMember("member1");
json["member1"].stringValue = "hello world";
Assert.That ( "hello world" == (string)json["member1"] );
}
示例4: PropertiesOrderTest
public void PropertiesOrderTest()
{
JsonObject data = new JsonObject ();
string json = "{\"first\":\"one\",\"second\":\"two\"," +
"\"third\":\"three\",\"fourth\":\"four\"}";
data.AddMember("first", "one");
data.AddMember("second", "two");
data.AddMember("third", "three");
data.AddMember("fourth", "four");
Assert.AreEqual (json, data.ToString ());
}
示例5: NullValue
public void NullValue()
{
string json = "{\"test\":null}";
JsonObject data = new JsonObject ();
data.AddMember("test", (string)null);
Assert.AreEqual (json, data.ToString ());
}
示例6: GetKeysTest
public void GetKeysTest()
{
JsonObject data = new JsonObject ();
data.AddMember("first", "one");
data.AddMember("second", "two");
data.AddMember("third", "three");
data.AddMember("fourth", "four");
//Assert.AreEqual (4, data.Count, "A1");
//foreach (string k in data.Keys)
// Assert.IsNotNull (data[k], "A2");
}
示例7: EqualsTest
public void EqualsTest()
{
JsonObject o = new JsonObject();
o.AddMember("member");
JsonValue a = o["member"];
JsonValue b;
// Compare ints
a.intValue = 7;
b = 7;
Assert.IsTrue (a.Equals (b), "A1");
Assert.IsFalse (a.Equals (null), "A2");
b = 8;
Assert.IsFalse (a.Equals (b), "A3");
// Compare longs
a.longValue = 10L;
b = 10L;
Assert.IsTrue (a.Equals (b), "A4");
// Compare Long and Int (the same value)
// NOTE:
// The expected behaviour of LitJson for (10.Equals(10L)) is False
// but Unity's Json will return True because that is more
// expected result in natural manner
b = 10;
Assert.AreEqual (10L.Equals(10), a.Equals (b), "A5");
// Compare Long and Long (different value)
b = 11L;
Assert.IsFalse (a.Equals (b), "A6");
// Compare doubles
a.doubleValue = 78.9;
b = 78.9;
Assert.IsTrue (a.Equals (b), "A7");
b = 78.899999;
Assert.IsFalse (a.Equals (b), "A8");
// Compare booleans
a.boolValue = true;
b = true;
Assert.IsTrue (a.Equals (b), "A9");
b.boolValue = false;
Assert.IsFalse (a.Equals (b), "A10");
// Compare strings
a.stringValue = "walrus";
b = "walrus";
Assert.IsTrue (a.Equals (b), "A11");
b = "Walrus";
Assert.IsFalse (a.Equals (b), "A12");
}
示例8: AsObjectTest
public void AsObjectTest()
{
JsonObject data = new JsonObject ();
data.AddMember("alignment", "left");
//data["alignment"] = "left";
data.AddMember("font", new JsonObject());
data["font"].AddMember("name", "Arial");
data["font"].AddMember("style", "italic");
data["font"].AddMember("size", 10);
data["font"].AddMember("color", "#fff");
Assert.IsTrue (data.isObject, "A1");
string json = @"{""alignment"":""left"",""font"":{""name"":""Arial"",""style"":""italic"",""size"":10,""color"":""#fff""}}";
//Debug.Log (data.ToString ());
Assert.AreEqual (json, data.ToString(), "A2");
}
示例9: ParseModifyAndToString
public void ParseModifyAndToString()
{
JsonObject json = new JsonObject();
json.ParseDocument(testInput1);
json.AddMember("category", "INIT");
json.AddMember("data_value","foobar");
JsonValue v = json["name1"];
json["name1"].SetString ("adsjlfajsdlfajsdflajs dsjfjdfajd.");
json["name2"].SetDouble(345.678);
Debug.Log (json.ToPrettyString ());
}