本文整理汇总了C#中JsonArray.ToJsonPrettyPrintString方法的典型用法代码示例。如果您正苦于以下问题:C# JsonArray.ToJsonPrettyPrintString方法的具体用法?C# JsonArray.ToJsonPrettyPrintString怎么用?C# JsonArray.ToJsonPrettyPrintString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonArray
的用法示例。
在下文中一共展示了JsonArray.ToJsonPrettyPrintString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateJsonTest
private void CreateJsonTest()
{
JsonArray weekDiet = new JsonArray();
for(int i=0;i<7;i++)
{
JsonObject diet = new JsonObject();
diet["DayNumber"] = i;
diet["Breakfast"] = "Banana"+ i;
diet["Lunch"] = "Banana"+ i;
diet["Dinner"] = "Banana"+ i;
diet["WithSugar"] = (i % 2 == 0);
diet["RandomNumber"] = Random.Range(0f,1.5f);
weekDiet.Add(diet);
}
for (int i=0;i<7;i++)
{
if (i % 2 == 1)
{
weekDiet[i]["RandomNumber"] = 3;
weekDiet[i]["RandomNumber"] = weekDiet[i]["RandomNumber"] * 2f;
}
}
Debug.Log("Test InputOutputFileTest done: \n"+ weekDiet.ToJsonPrettyPrintString());
}
示例2: JsonExample
public JsonExample()
{
//Object creation, all types extends from JsonNode,
JsonArray arrayExample = new JsonArray();
JsonObject objectExample = new JsonObject();
JsonObject objectExample2 = new JsonObject();
string outPutString;
string outPutPrettyPrintString;
//Basic types can be created with JsonBasic or directly the type you want.
int basicIntExample = 17;
//Adding or removing components, it's the same like you were using a Dictionary (JsonObject) or a List (JsonArray)
arrayExample.Add(objectExample);
arrayExample.Add(objectExample2);
objectExample["name"] = "Ángel";
objectExample["age"] = basicIntExample;
objectExample["programmer"] = true;
objectExample["glasses"] = null; //Yes it has all basic types of Json including null :)
//You can do operations with JsonNodes like if they were the primitive types without casting them
objectExample["age"] = objectExample["age"] + 10;
objectExample2["name"] = "Manolo";
objectExample2["age"] = 54.4f;
objectExample2["programmer"] = false;
objectExample2["glasses"] = new JsonArray() { "sunglases", 3, null};
//Also you can iterate through JsonArray and JsonObject(also using .Keys, .Values like dictionary)
foreach(JsonObject personObject in arrayExample)
{
personObject["surname"] = "Surname";
}
//yes it has basic string, no spaces, no tabs, not end lines
outPutString = arrayExample.ToJsonString();
/*
outPutString :
[{"name":"Ángel","age":27,"programmer":true,"glasses":null,"surname":"Surname"},{"name":"Manolo","age":54.4,"programmer":false,"glasses":["sunglases",3,null],"surname":"Surname"}]
*/
//yes it has pretty pring string, with spaces, tabs, endlines):
outPutPrettyPrintString = arrayExample.ToJsonPrettyPrintString();
/*
outPutPrettyPrintString :
[
{
"name": "Ángel",
"age": 27,
"programmer": true,
"glasses": null,
"surname": "Surname"
},
{
"name": "Manolo",
"age": 54.4,
"programmer": false,
"glasses": [
"sunglases",
3,
null
],
"surname": "Surname"
}
]
*/
//Also you can configurate the Json.IDENT_CHAR (\t,' ',whatever you want) and Json.PRETTYPRINT_IDENT_COUNT (for number of times you want to repeat char per ident)
//Parsing json it's easy :)
arrayExample = (JsonArray) JsonNode.ParseJsonString(outPutString);
}