本文整理汇总了C#中Newtonsoft.Json.JsonTextWriter.WriteEndConstructor方法的典型用法代码示例。如果您正苦于以下问题:C# JsonTextWriter.WriteEndConstructor方法的具体用法?C# JsonTextWriter.WriteEndConstructor怎么用?C# JsonTextWriter.WriteEndConstructor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.JsonTextWriter
的用法示例。
在下文中一共展示了JsonTextWriter.WriteEndConstructor方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: XmlToJson
public string XmlToJson(string Xml)
{
StringWriter JW = new StringWriter();
JsonTextWriter JTW = new JsonTextWriter(JW);
JTW.Formatting = Newtonsoft.Json.Formatting.Indented;
StringReader XSR = new StringReader(Xml.Trim());
XmlReader XR = XmlReader.Create(XSR);
string ValType = "";
bool InArray = false;
XR.Read();
if (!(XR.NodeType == XmlNodeType.Element && XR.Name == "xml"))
{
throw new Exception("Invalid XML Input");
}
bool Read = true;
bool NextRead = false;
try
{
if (XR.GetAttribute("in_array") == "1") InArray = true;
}
catch{}
while (Read)
{
if (! NextRead)
{
Read = XR.Read();
}
NextRead = false;
switch(XR.NodeType)
{
case (XmlNodeType.Element):
switch(XR.Name)
{
case("obj"):
JTW.WriteStartObject();
break;
case ("arr"):
JTW.WriteStartArray();
break;
case("cons" ):
JTW.WriteStartConstructor("");
break;
case ("num"):
case ("str"):
case ("bool"):
case ("undef" ):
ValType = XR.Name;
Read = XR.Read();
NextRead = true;
if (XR.NodeType == XmlNodeType.EndElement)
{
JTW.WriteValue("");
}
break;
case("prop"):
JTW.WritePropertyName(XR.GetAttribute("oname"));
break;
}
break;
case (XmlNodeType.EndElement ):
switch(XR.Name)
{
case("obj"):
JTW.WriteEndObject();
break;
case("arr"):
JTW.WriteEndArray();
break;
case("cons" ):
JTW.WriteEndConstructor();
break;
}
break;
case(XmlNodeType.Text):
switch(ValType)
{
case("num"):
try
{
JTW.WriteValue(Int32.Parse(XR.Value.Trim()));
}
catch
{
try
{
JTW.WriteValue(float.Parse(XR.Value.Trim()));
}
catch
{
JTW.WriteValue(XR.Value);
}
}
break;
case("str"):
JTW.WriteValue(XR.Value.ToString());
break;
//.........这里部分代码省略.........
示例2: WriteObjectNestedInConstructor
public void WriteObjectNestedInConstructor()
{
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
using (JsonWriter jsonWriter = new JsonTextWriter(sw))
{
jsonWriter.WriteStartObject();
jsonWriter.WritePropertyName("con");
jsonWriter.WriteStartConstructor("Ext.data.JsonStore");
jsonWriter.WriteStartObject();
jsonWriter.WritePropertyName("aa");
jsonWriter.WriteValue("aa");
jsonWriter.WriteEndObject();
jsonWriter.WriteEndConstructor();
jsonWriter.WriteEndObject();
}
Assert.AreEqual(@"{""con"":new Ext.data.JsonStore({""aa"":""aa""})}", sb.ToString());
}
示例3: SyncJsonObjectTypes
//.........这里部分代码省略.........
{
Writer.WriteValue(New.Value);
}
}
else if ((Old.TokenType == JsonToken.Boolean) && (New.TokenType != JsonToken.Boolean))
{
string Value = New.Value.ToString();
if (Value.Equals("true"))
{
Writer.WriteValue(true);
}
else if (Value.Equals("false"))
{
Writer.WriteValue(false);
}
else
{
Writer.WriteValue(New.Value);
}
}
else if ((Old.TokenType == JsonToken.String) && (New.TokenType == JsonToken.Null))
{
Writer.WriteValue("");
}
else if ((Old.TokenType == JsonToken.StartArray) && (New.TokenType == JsonToken.String))
{
Old.Read();
if (Old.TokenType == JsonToken.EndArray)
{
Writer.WriteValue(JsonToken.StartArray);
if (New.Value.ToString() != "") Writer.WriteValue(New.Value);
Writer.WriteValue(JsonToken.EndArray);
}
else
{
Writer.WriteValue(New.Value);
}
}
else
{
if (Old.TokenType != New.TokenType)
{
Writer.Close();
New.Close();
Old.Close();
return NewJson;
}
else if (New.TokenType == JsonToken.PropertyName)
{
if (Old.Value == null || New.Value == null)
{
Writer.Close();
New.Close();
Old.Close();
return NewJson;
}
else if (!Old.Value.ToString().Equals(New.Value.ToString()))
{
Writer.Close();
New.Close();
Old.Close();
return NewJson;
}
}
switch (New.TokenType)
{
case JsonToken.StartConstructor:
Writer.WriteStartConstructor("");
break;
case JsonToken.EndConstructor:
Writer.WriteEndConstructor();
break;
case JsonToken.StartObject:
Writer.WriteStartObject();
break;
case JsonToken.EndObject:
Writer.WriteEndObject();
break;
case JsonToken.StartArray:
Writer.WriteStartArray();
break;
case JsonToken.EndArray:
Writer.WriteEndArray();
break;
case JsonToken.PropertyName:
Writer.WritePropertyName(New.Value.ToString());
break;
case JsonToken.String:
case JsonToken.Integer:
case JsonToken.Boolean:
case JsonToken.Date:
case JsonToken.Null:
case JsonToken.Float:
Writer.WriteValue(New.Value);
break;
}
}
}
return SW.ToString();
}