本文整理汇总了C#中JObject.ToJSON方法的典型用法代码示例。如果您正苦于以下问题:C# JObject.ToJSON方法的具体用法?C# JObject.ToJSON怎么用?C# JObject.ToJSON使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JObject
的用法示例。
在下文中一共展示了JObject.ToJSON方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
if (false)
{
/////////////////////////
// Stringifier Test
/////////////////////////
// implicity conversion
JArray jArrTest = new JArray();
jArrTest.Value.Add("jArrTest primitive string");
Console.WriteLine(jArrTest.ToJSON());
JString jStrTest = null;
jStrTest = "primitive string test";
Console.WriteLine(jStrTest.ToJSON());
// Null tests
JString jstr = new JString(null);
Console.WriteLine(jstr.ToJSON());
// string with a backward slash
JString jstrslash = new JString("\\\\n\n");
JObject jobjslash = new JObject();
jobjslash.Items.Add("\r\n\\\n", jstrslash);
Console.WriteLine(jobjslash.ToJSON());
// stringify a jstring that contain break line
JString breakstr = new JString("abc \n cba");
Console.WriteLine(breakstr.ToJSON());
JObject jNullObj = new JObject();
jNullObj["test1"] = new JNumber(23);
jNullObj["test2"] = null;
jNullObj["test3"] = new JString(null);
jNullObj["test4"] = new JArray();
((JArray)jNullObj["test4"]).Value.Add(new JNumber(234));
((JArray)jNullObj["test4"]).Value.Add(null);
((JArray)jNullObj["test4"]).Value.Add(new JString("sdf"));
Console.WriteLine(jNullObj.ToJSON());
// Array tests
JObject testObject = new JObject();
testObject.Items.Add("key1", new JBoolean(false));
testObject.Items.Add("key2", new JNumber(333));
JArray testArray = new JArray(new JSONObject[] {
new JBoolean(false),
new JBoolean(true),
new JNumber(20),
new JString("test"),
testObject,
new JNumber(0)
});
Console.WriteLine(testArray.ToJSON());
// test JArray.this[int index]
Console.WriteLine(((JNumber)testArray[2]).Value.ToString());
Console.WriteLine(((JNumber)testArray[2]).Value = 556);
Console.WriteLine(testArray.ToJSON());
// test JArray.this[string key]
testArray["alimali"] = new JString("alimali");
Console.WriteLine(testArray["alimali"].ToJSON());
Console.WriteLine(testArray.ToJSON());
// test implicit convert from int to JNumber
Console.WriteLine((testArray[2] = (JNumber)234).ToJSON());
Console.WriteLine(testArray.ToJSON());
// test implicit convert from string to JString
Console.WriteLine((testArray[2] = (JString)"jstring converted!").ToJSON());
Console.WriteLine(testArray.ToJSON());
}
else
{
/////////////////////////
// Parser Test
/////////////////////////
// unicode tests
JArray unicode1 = (JArray)Helpers.Parse(@"['HR\u9762\u8bd5',3,3,4]");
// array tests
JArray array = (JArray)Helpers.Parse(@"[1,3,3,4]");
JObject array2 = (JObject)Helpers.Parse(@"{'Processes':['20ed6436-5b44-47f8-8642-1184811d4a99']}");
JObject array3 = (JObject)Helpers.Parse(@"{'Processes':['20ed6436-5b44-47f8-8642-1184811d4a99','20ed6436-5b44-47f8-8642-1184811d4a99']}");
JObject array4 = (JObject)Helpers.Parse(@"{'name': 'asfdasf', 'items': [{'name': 'HR\u9762\u8bd5'},{'name': '\u4f53\u68c0'},{'name': '\u5165\u804c'},{'name': '\u5ba2\u6237\u9762\u8bd5'},{'name': '\u7b7e\u7f72OFFER'},{'name': '\u90e8\u95e8\u9762\u8bd5'}]}");
// positive tests
JObject p_number1 = (JObject)Helpers.Parse(@"{""test"":23423}");
JObject p_number2_blank = (JObject)Helpers.Parse(@" { ""test"" : 23423 } ");
//.........这里部分代码省略.........