本文整理汇总了C#中JSONNode.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# JSONNode.ToString方法的具体用法?C# JSONNode.ToString怎么用?C# JSONNode.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSONNode
的用法示例。
在下文中一共展示了JSONNode.ToString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EmptyStrings
public void EmptyStrings()
{
JSONNode root = new JSONNode();
root["root"]["X"].asText = string.Empty;
root["root"]["Y"].asText = "";
root["root"]["Z"].asText = null;
Assert.AreEqual("", root["root"]["X"].asText);
Assert.AreEqual("", root["root"]["Y"].asText);
Assert.AreEqual(null, root["root"]["Z"].asText);
string jsonString = "";
jsonString = root.ToString();
Console.WriteLine(jsonString);
var n = JSONNode.CreateFromString(jsonString);
Assert.AreEqual(string.Empty, n["root"]["Y"].asText);
Assert.AreEqual("", n["root"]["Y"].asText);
Assert.AreEqual(null, n["root"]["Z"].asText);
}
示例2: TestEscapeChar
void TestEscapeChar(char c)
{
var x = new JSONNode();
x[c.ToString()].asText = c.ToString();
string testString = x.ToString();
Console.WriteLine(testString);
var y = JSONNode.CreateFromString(testString);
Assert.AreEqual(x.ToString(), y.ToString());
Assert.AreEqual(y[c.ToString()].asText[0], c);
Assert.AreEqual(x[c.ToString()].asText[0], c);
}
示例3: SpecialTest
public void SpecialTest()
{
JSONNode n = new JSONNode();
n["root"]["D"][0].asText = "1";
n["root"]["D"][1].asText = "1";
n["root"]["D"][2].asText = "1";
n["root"]["D"][3].asText = "1";
n["root"]["D"][4].asText = "1";
n["root"]["D"][5]["qwert"].asText = "hundred";
n["root"]["E"].asNumber = 1;
n["root"]["G"].asNumber = 2;
n["root"]["F"].asNumber = 3;
n["root"]["myObjecy"]["test Array"][0].asText = "text";
//Console.WriteLine(n.data);
string json = n.ToString();
Console.WriteLine(json);
Tokenizer w = new Tokenizer();
w.ParseText(new StringReader(json));
//foreach (var s in result)
// Console.WriteLine(s);
Generator g = new Generator();
var newNode = g.Generate(json);
Console.WriteLine("OUT" + newNode["root"]["D"][5]["qwert"].asText);
}
示例4: SaveLoad
public void SaveLoad()
{
List<string> s = new List<string>
{
"one", "two", "three", null, "five"
};
JSONNode n = new JSONNode()["root"];
n["cash"].asInt = 10;
n["diamonds"].asInt = 100;
SaveArray(n["saved numbers"], s);
SaveArray(n["saved"][0], s);
var json = n.ToString();
JSONNode loaded = JSONNode.CreateFromString(json);
Assert.AreEqual(loaded.ToString(), json);
Console.WriteLine(json);
List<string> tmpList = new List<string>();
LoadArray(loaded["saved numbers"], tmpList);
for (int i = 0; i < s.Count; ++i)
{
Assert.AreEqual(s[i], tmpList[i]);
}
tmpList.Clear();
LoadArray(loaded["saved"][0], tmpList);
for (int i = 0; i < s.Count; ++i)
{
Assert.AreEqual(s[i], tmpList[i]);
}
tmpList.Clear();
Console.Write(json);
}
示例5: HeroTestB
public void HeroTestB()
{
JSONNode n = new JSONNode();
n["playerInfo"]["cash"].asInt = 10;
n["playerInfo"]["diamonds"].asInt = 10;
n["playerInfo"]["selectedAttributes"][0].asText = "StandardSubmarine 2";
n["playerInfo"]["attributes"][0].asText = "StandardSubmarine";
n["playerInfo"]["attributes"][1].asText = "StandardSubmarine 2";
string data = "{\"playerInfo\":{\"cash\":10,\"diamonds\":10,\"selectedAttributes\":[\"StandardSubmarine 2\"],\"attributes\":[\"StandardSubmarine\",\"StandardSubmarine 2\"]}}";
Assert.AreEqual(n.ToString(), data);
}
示例6: SetDataByEntity
public virtual void SetDataByEntity(int entityId, int componentId, JSONNode data)
{
PlayerPrefs.SetString(entityId + "_" + componentId, data.ToString());
}