本文整理汇总了C#中JsonWriter.WriteObjectEnd方法的典型用法代码示例。如果您正苦于以下问题:C# JsonWriter.WriteObjectEnd方法的具体用法?C# JsonWriter.WriteObjectEnd怎么用?C# JsonWriter.WriteObjectEnd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonWriter
的用法示例。
在下文中一共展示了JsonWriter.WriteObjectEnd方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Write
/// <summary>
/// Write this target to a JsonWriter
/// </summary>
/// <param name="Writer">Writer to output to</param>
void Write(JsonWriter Writer)
{
Writer.WriteObjectStart();
Writer.WriteValue("Name", Name);
Writer.WriteValue("LoadingPolicy", LoadingPolicy.ToString());
Writer.WriteObjectEnd();
}
示例2: WriteResponseForPostJson
void WriteResponseForPostJson(HttpRequest request, HttpResponse response)
{
// read request JSON
uint requestedCount = ReadCount(request.Body);
// write response JSON
var json = new JsonWriter<ResponseFormatter>(response.Body, prettyPrint: false);
json.WriteObjectStart();
json.WriteArrayStart();
for (int i = 0; i < requestedCount; i++) {
json.WriteString("hello!");
}
json.WriteArrayEnd();
json.WriteObjectEnd();
// write headers
var headers = response.Headers;
headers.AppendHttpStatusLine(HttpVersion.V1_1, 200, new Utf8String("OK"));
headers.Append("Content-Length : ");
headers.Append(response.Body.CommitedBytes);
headers.AppendHttpNewLine();
headers.Append("Content-Type : text/plain; charset=UTF-8");
headers.AppendHttpNewLine();
headers.Append("Server : .NET Core Sample Server");
headers.AppendHttpNewLine();
headers.Append("Date : ");
headers.Append(DateTime.UtcNow, 'R');
headers.AppendHttpNewLine();
headers.AppendHttpNewLine();
}
示例3: Write
static void Write(JsonWriter json)
{
json.WriteObjectStart();
json.WriteAttribute("age", 30);
json.WriteAttribute("first", "John");
json.WriteAttribute("last", "Smith");
json.WriteMember("phoneNumbers");
json.WriteArrayStart();
json.WriteString("425-000-1212");
json.WriteString("425-000-1213");
json.WriteArrayEnd();
json.WriteMember("address");
json.WriteObjectStart();
json.WriteAttribute("street", "1 Microsoft Way");
json.WriteAttribute("city", "Redmond");
json.WriteAttribute("zip", 98052);
json.WriteObjectEnd();
json.WriteObjectEnd();
}
示例4: Write
/// <summary>
/// Reads a list of build steps from a Json project or plugin descriptor
/// </summary>
/// <param name="RawObject">The json descriptor object</param>
/// <param name="FieldName">Name of the field to read</param>
/// <param name="OutBuildSteps">Output variable to store the sorted dictionary that was read</param>
/// <returns>True if the field was read (and OutBuildSteps is set), false otherwise.</returns>
public void Write(JsonWriter Writer, string FieldName)
{
Writer.WriteObjectStart(FieldName);
foreach(KeyValuePair<UnrealTargetPlatform, string[]> Pair in HostPlatformToCommands)
{
Writer.WriteArrayStart(Pair.Key.ToString());
foreach(string Line in Pair.Value)
{
Writer.WriteValue(Line);
}
Writer.WriteArrayEnd();
}
Writer.WriteObjectEnd();
}
示例5: ToString
public override string ToString()
{
StringBuilder sb = new StringBuilder ();
JsonWriter writer = new JsonWriter (sb);
writer.WriteObjectStart ();
writer.WritePropertyName ("option");
writer.Write (option);
writer.WritePropertyName ("subfield");
writer.Write (subfield);
writer.WritePropertyName ("tarId");
writer.Write (tarId);
writer.WriteObjectEnd ();
return sb.ToString();
}
示例6: Deactivate
void Deactivate()
{
state = 0;
renderer.material.color = colours[0];
StringBuilder sb = new StringBuilder();
JsonWriter writer = new JsonWriter(sb);
writer.WriteObjectStart();
writer.WritePropertyName("id");
writer.Write(id);
writer.WritePropertyName("state");
writer.Write(0);
writer.WriteObjectEnd();
monome.SendMessage("SendToSaul", sb.ToString());
}
示例7: SaveJson
public static void SaveJson()
{
string filePath = Application.dataPath + @"/StringAssets/file/pos.txt";
FileInfo fileInfo = new FileInfo(filePath);
if (!File.Exists(filePath))
{
File.Delete(filePath);
}
StreamWriter sw = fileInfo.CreateText();
StringBuilder sb = new StringBuilder();
JsonWriter writer = new JsonWriter(sb);
//从场景中开始一个个的遍历
foreach (EditorBuildSettingsScene s in EditorBuildSettings.scenes)
{
if (s.enabled == true)
{
string name = s.path;
EditorApplication.OpenScene(name);
GameObject parent = GameObject.Find("PosObj");
if (parent)
{
writer.WriteArrayStart(); //开始写数据
for (int i = 0; i < parent.transform.childCount; i++)
{
Transform obj = parent.transform.GetChild(i);
writer.WriteObjectStart();
writer.WritePropertyName(obj.name);
writer.Write(obj.position.x.ToString() + "," + obj.position.y.ToString() + "," +
obj.position.z.ToString());
writer.WriteObjectEnd();
}
writer.WriteArrayEnd();
}
}
}
sw.WriteLine(sb.ToString());
sw.Close();
sw.Dispose(); //关闭文件流
AssetDatabase.Refresh(); //刷新
}
示例8: PostTest1
IEnumerator PostTest1()
{
string str = @"";
// string like this
// str = @"{""Id"":0,""IMEI"":""String"",""Phone"":""String"",""Name"":""String"",""Status"":0,""CreateTime"":""\/Date(-62135596800000+0800)\/"",""UpdateTime"":""\/Date(-62135596800000+0800)\/""}";
// write Json
JsonWriter writer = new JsonWriter();
writer.WriteObjectStart();
writer.WritePropertyName("Id");
writer.Write(0);
writer.WritePropertyName("IMEI");
writer.Write("7654321");
writer.WritePropertyName("Phone");
writer.Write("13802817183");
writer.WritePropertyName("Name");
writer.Write("bbzm");
writer.WritePropertyName("Status");
writer.Write("1");
writer.WritePropertyName("CreateTime");
writer.Write("2013-01-01");
writer.WritePropertyName("UpdateTime");
writer.Write("2013-10-10");
writer.WriteObjectEnd();
str = writer.ToString();
Debug.Log(str);
WWWForm parameter = new WWWForm();
parameter.AddField("Body", str);
WWW postRequest = new WWW(@"http://192.168.133.225:82/Client/123456?format=json", parameter);
yield return postRequest;
JsonReader read = new JsonReader(postRequest.text);
Debug.Log(postRequest.text);
Debug.Log(" ----------------- ");
while (read.Read())
{
Debug.Log(read.Token + " : " + read.Value + " : " + read.GetType().ToString());
}
Debug.Log(" ----------------- ");
}
示例9: SaveData
/// <summary>
/// 数据存Json
/// </summary>
public void SaveData()
{
StringBuilder sb = new StringBuilder();
JsonWriter jw = new JsonWriter(sb);
jw.WriteObjectStart();
//写入玩家名称
jw.WritePropertyName("Name");
jw.Write(GlobalManager.userName);
//写入开始索引
jw.WritePropertyName("StartIndex");
jw.Write(GlobalManager.startIndex);
//写入最高分
jw.WritePropertyName("MaxScore");
jw.Write(GlobalManager.maxScore);
//写入已经完成的单词总数
jw.WritePropertyName("WordAmount");
jw.Write(GlobalManager.wordAmount);
//...
jw.WriteObjectEnd();
SaveJsonString(sb.ToString());
}
示例10: WriteResponseForPostJson
// This method is a bit of a mess. We need to fix many Http and Json APIs
void WriteResponseForPostJson(BufferFormatter formatter, HttpRequestLine requestLine, ReadOnlySpan<byte> body)
{
Console.WriteLine(new Utf8String(body));
uint requestedCount = ReadCountUsingReader(body).GetValueOrDefault(1);
//uint requestedCount = ReadCountUsingNonAllocatingDom(body).GetValueOrDefault(1);
// TODO: this needs to be written directly to the buffer after content length reservation is implemented.
var buffer = ArrayPool<byte>.Shared.Rent(2048);
var spanFormatter = new SpanFormatter(buffer.Slice(), FormattingData.InvariantUtf8);
var json = new JsonWriter<SpanFormatter>(spanFormatter, prettyPrint: true);
json.WriteObjectStart();
json.WriteArrayStart();
for (int i = 0; i < requestedCount; i++) {
json.WriteString(DateTime.UtcNow.ToString()); // TODO: this needs to not allocate.
}
json.WriteArrayEnd(); ;
json.WriteObjectEnd();
var responseBodyText = new Utf8String(buffer, 0, spanFormatter.CommitedByteCount);
formatter.AppendHttpStatusLine(HttpVersion.V1_1, 200, new Utf8String("OK"));
formatter.Append(new Utf8String("Content-Length : "));
formatter.Append(responseBodyText.Length);
formatter.AppendHttpNewLine();
formatter.Append("Content-Type : text/plain; charset=UTF-8");
formatter.AppendHttpNewLine();
formatter.Append("Server : .NET Core Sample Serve");
formatter.AppendHttpNewLine();
formatter.Append(new Utf8String("Date : "));
formatter.Append(DateTime.UtcNow.ToString("R"));
formatter.AppendHttpNewLine();
formatter.AppendHttpNewLine();
formatter.Append(responseBodyText);
ArrayPool<byte>.Shared.Return(buffer);
}
示例11: MergerJson
public void MergerJson()
{
StringBuilder sb = new StringBuilder ();
JsonWriter writer = new JsonWriter (sb);
writer.WriteObjectStart ();
writer.WritePropertyName ("Name");
writer.Write ("yusong");
writer.WritePropertyName ("Age");
writer.Write (26);
writer.WritePropertyName ("Girl");
writer.WriteArrayStart ();
writer.WriteObjectStart();
writer.WritePropertyName("name");
writer.Write("ruoruo");
writer.WritePropertyName("age");
writer.Write(24);
writer.WriteObjectEnd ();
writer.WriteObjectStart();
writer.WritePropertyName("name");
writer.Write("momo");
writer.WritePropertyName("age");
writer.Write(26);
writer.WriteObjectEnd ();
writer.WriteArrayEnd();
writer.WriteObjectEnd ();
Debug.Log(sb.ToString ());
JsonData jd = JsonMapper.ToObject(sb.ToString ());
Debug.Log("name = " + (string)jd["Name"]);
Debug.Log("Age = " + (int)jd["Age"]);
JsonData jdItems = jd["Girl"];
for (int i = 0; i < jdItems.Count; i++)
{
Debug.Log("Girl name = " + jdItems[i]["name"]);
Debug.Log("Girl age = " + (int)jdItems[i]["age"]);
}
}
示例12: ToString
public override string ToString()
{
StringBuilder sb = new StringBuilder ();
JsonWriter writer = new JsonWriter (sb);
writer.WriteObjectStart ();
writer.WritePropertyName ("id");
writer.Write (id);
if (type == DialogType.Dialog) {
writer.WritePropertyName ("type");
writer.Write ("Dialog");
writer.WritePropertyName ("content");
writer.Write (content);
writer.WritePropertyName ("delay");
writer.Write (delay);
writer.WritePropertyName ("voice");
writer.Write (voice);
} else {
writer.WritePropertyName ("type");
writer.Write ("Select");
writer.WritePropertyName ("select1");
writer.Write (select[0].ToString());
writer.WritePropertyName ("select2");
writer.Write (select[1].ToString());
writer.WritePropertyName ("delay");
writer.Write (delay);
}
writer.WriteObjectEnd ();
return sb.ToString ();
}
示例13: Export
/// <summary>
/// Export the build graph to a Json file, for parallel execution by the build system
/// </summary>
/// <param name="File">Output file to write</param>
/// <param name="Trigger">The trigger whose nodes to run. Null for the default nodes.</param>
/// <param name="CompletedNodes">Set of nodes which have been completed</param>
public void Export(FileReference File, ManualTrigger Trigger, HashSet<Node> CompletedNodes)
{
// Find all the nodes which we're actually going to execute. We'll use this to filter the graph.
HashSet<Node> NodesToExecute = new HashSet<Node>();
foreach(Node Node in Agents.SelectMany(x => x.Nodes))
{
if(!CompletedNodes.Contains(Node) && Node.IsBehind(Trigger))
{
NodesToExecute.Add(Node);
}
}
// Open the output file
using(JsonWriter JsonWriter = new JsonWriter(File.FullName))
{
JsonWriter.WriteObjectStart();
// Write all the agents
JsonWriter.WriteArrayStart("Groups");
foreach(Agent Agent in Agents)
{
Node[] Nodes = Agent.Nodes.Where(x => NodesToExecute.Contains(x) && x.ControllingTrigger == Trigger).ToArray();
if(Nodes.Length > 0)
{
JsonWriter.WriteObjectStart();
JsonWriter.WriteValue("Name", Agent.Name);
JsonWriter.WriteArrayStart("Agent Types");
foreach(string AgentType in Agent.PossibleTypes)
{
JsonWriter.WriteValue(AgentType);
}
JsonWriter.WriteArrayEnd();
JsonWriter.WriteArrayStart("Nodes");
foreach(Node Node in Nodes)
{
JsonWriter.WriteObjectStart();
JsonWriter.WriteValue("Name", Node.Name);
JsonWriter.WriteValue("DependsOn", String.Join(";", Node.GetDirectOrderDependencies().Where(x => NodesToExecute.Contains(x) && x.ControllingTrigger == Trigger)));
JsonWriter.WriteObjectStart("Notify");
JsonWriter.WriteValue("Default", String.Join(";", Node.NotifyUsers));
JsonWriter.WriteValue("Submitters", String.Join(";", Node.NotifySubmitters));
JsonWriter.WriteValue("Warnings", Node.bNotifyOnWarnings);
JsonWriter.WriteObjectEnd();
JsonWriter.WriteObjectEnd();
}
JsonWriter.WriteArrayEnd();
JsonWriter.WriteObjectEnd();
}
}
JsonWriter.WriteArrayEnd();
// Write all the badges
JsonWriter.WriteArrayStart("Badges");
foreach (Badge Badge in Badges)
{
Node[] Dependencies = Badge.Nodes.Where(x => NodesToExecute.Contains(x)).ToArray();
if (Dependencies.Length > 0)
{
// Reduce that list to the smallest subset of direct dependencies
HashSet<Node> DirectDependencies = new HashSet<Node>(Dependencies);
foreach (Node Dependency in Dependencies)
{
DirectDependencies.ExceptWith(Dependency.OrderDependencies);
}
JsonWriter.WriteObjectStart();
JsonWriter.WriteValue("Name", Badge.Name);
if (!String.IsNullOrEmpty(Badge.Project))
{
JsonWriter.WriteValue("Project", Badge.Project);
}
JsonWriter.WriteValue("AllDependencies", String.Join(";", Agents.SelectMany(x => x.Nodes).Where(x => Dependencies.Contains(x)).Select(x => x.Name)));
JsonWriter.WriteValue("DirectDependencies", String.Join(";", DirectDependencies.Select(x => x.Name)));
JsonWriter.WriteObjectEnd();
}
}
JsonWriter.WriteArrayEnd();
// Write all the triggers and reports.
JsonWriter.WriteArrayStart("Reports");
foreach (Report Report in NameToReport.Values)
{
Node[] Dependencies = Report.Nodes.Where(x => NodesToExecute.Contains(x)).ToArray();
if (Dependencies.Length > 0)
{
// Reduce that list to the smallest subset of direct dependencies
HashSet<Node> DirectDependencies = new HashSet<Node>(Dependencies);
foreach (Node Dependency in Dependencies)
{
DirectDependencies.ExceptWith(Dependency.OrderDependencies);
}
JsonWriter.WriteObjectStart();
JsonWriter.WriteValue("Name", Report.Name);
//.........这里部分代码省略.........
示例14: WriteJsonToFile
void WriteJsonToFile(string path, string fileName)
{
System.Text.StringBuilder strB = new System.Text.StringBuilder();
JsonWriter jsWrite = new JsonWriter(strB);
jsWrite.WriteObjectStart();
jsWrite.WritePropertyName("Monster");
jsWrite.WriteArrayStart();
jsWrite.WriteObjectStart();
jsWrite.WritePropertyName("MonsterName");
jsWrite.Write("Person");
jsWrite.WritePropertyName("attack");
jsWrite.Write(10);
jsWrite.WritePropertyName("defense");
jsWrite.Write(10);
jsWrite.WritePropertyName("weapon");
jsWrite.Write("Sword");
jsWrite.WriteObjectEnd();
jsWrite.WriteObjectStart();
jsWrite.WritePropertyName("MonsterName");
jsWrite.Write("Animal");
jsWrite.WritePropertyName("attack");
jsWrite.Write(8);
jsWrite.WritePropertyName("defense");
jsWrite.Write(15);
jsWrite.WritePropertyName("weapon");
jsWrite.Write("tooth");
jsWrite.WriteObjectEnd();
jsWrite.WriteObjectStart();
jsWrite.WritePropertyName("MonsterName");
jsWrite.Write("Dragon");
jsWrite.WritePropertyName("attack");
jsWrite.Write(100);
jsWrite.WritePropertyName("defense");
jsWrite.Write(200);
jsWrite.WritePropertyName("weapon");
jsWrite.Write("fire breath");
jsWrite.WriteObjectEnd();
jsWrite.WriteArrayEnd();
jsWrite.WriteObjectEnd();
Debug.Log(strB);
//创建文件目录
DirectoryInfo dir = new DirectoryInfo(path);
if (dir.Exists)
{
Debug.Log("This file is already exists");
}
else
{
Directory.CreateDirectory(path);
Debug.Log("CreateFile");
#if UNITY_EDITOR
AssetDatabase.Refresh();
#endif
}
//把json数据写到txt里
StreamWriter sw;
if (File.Exists(fileName))
{
//如果文件存在,那么就向文件继续附加(为了下次写内容不会覆盖上次的内容)
sw = File.AppendText(fileName);
Debug.Log("appendText");
}
else
{
//如果文件不存在则创建文件
sw = File.CreateText(fileName);
Debug.Log("createText");
}
sw.WriteLine(strB);
sw.Close();
#if UNITY_EDITOR
AssetDatabase.Refresh();
#endif
}
示例15: WriteJsonAndPrint
void WriteJsonAndPrint()
{
System.Text.StringBuilder strB = new System.Text.StringBuilder();
JsonWriter jsWrite = new JsonWriter(strB);
jsWrite.WriteObjectStart();
jsWrite.WritePropertyName("Name");
jsWrite.Write("taotao");
jsWrite.WritePropertyName("Age");
jsWrite.Write(25);
jsWrite.WritePropertyName("MM");
jsWrite.WriteArrayStart();
jsWrite.WriteObjectStart();
jsWrite.WritePropertyName("name");
jsWrite.Write("xiaomei");
jsWrite.WritePropertyName("age");
jsWrite.Write("17");
jsWrite.WriteObjectEnd();
jsWrite.WriteObjectStart();
jsWrite.WritePropertyName("name");
jsWrite.Write("xiaoli");
jsWrite.WritePropertyName("age");
jsWrite.Write("18");
jsWrite.WriteObjectEnd();
jsWrite.WriteArrayEnd();
jsWrite.WriteObjectEnd();
Debug.Log(strB);
JsonData jd = JsonMapper.ToObject(strB.ToString());
Debug.Log("name=" + jd["Name"]);
Debug.Log("age=" + jd["Age"]);
JsonData jdItems = jd["MM"];
for (int i = 0; i < jdItems.Count; i++)
{
Debug.Log("MM name=" + jdItems["name"]);
Debug.Log("MM age=" + jdItems["age"]);
}
}