本文整理汇总了C#中Newtonsoft.Json.JsonWriter.Close方法的典型用法代码示例。如果您正苦于以下问题:C# JsonWriter.Close方法的具体用法?C# JsonWriter.Close怎么用?C# JsonWriter.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.JsonWriter
的用法示例。
在下文中一共展示了JsonWriter.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FromHashtableQueue
public static string FromHashtableQueue(Queue<Hashtable> queue)
{
StringWriter textWriter = new StringWriter();
JsonWriter jsonWriter = new JsonWriter(textWriter);
jsonWriter.WriteStartArray();
JsonSerializer serializer = new JsonSerializer();
UUIDConverter UUID = new UUIDConverter();
serializer.Converters.Add(UUID);
while (queue.Count > 0)
{
try
{
Hashtable hashtable = queue.Dequeue();
serializer.Serialize(jsonWriter, hashtable);
}
catch(Exception e)
{
AjaxLife.Debug("MakeJson.FromHashTable", e.Message);
}
}
jsonWriter.WriteEndArray();
jsonWriter.Flush();
string text = textWriter.ToString();
jsonWriter.Close();
textWriter.Dispose();
return text;
}
示例2: FromObject
public static string FromObject(object obj)
{
StringWriter textWriter = new StringWriter();
JsonWriter jsonWriter = new JsonWriter(textWriter);
JsonSerializer serializer = new JsonSerializer();
LLUUIDConverter UUID = new LLUUIDConverter();
serializer.Converters.Add(UUID);
serializer.Serialize(jsonWriter, obj);
jsonWriter.Flush();
string text = textWriter.ToString();
jsonWriter.Close();
textWriter.Dispose();
return text;
}
示例3: FromHashtableQueue
public static string FromHashtableQueue(Queue<Hashtable> queue)
{
StringWriter textWriter = new StringWriter();
JsonWriter jsonWriter = new JsonWriter(textWriter);
jsonWriter.WriteStartArray();
JsonSerializer serializer = new JsonSerializer();
LLUUIDConverter UUID = new LLUUIDConverter();
serializer.Converters.Add(UUID);
while (queue.Count > 0)
{
Hashtable hashtable = queue.Dequeue();
serializer.Serialize(jsonWriter, hashtable);
}
jsonWriter.WriteEndArray();
jsonWriter.Flush();
string text = textWriter.ToString();
jsonWriter.Close();
textWriter.Dispose();
return text;
}
示例4: Serialize
internal string Serialize(IEnumerable<EventData> events)
{
if (events == null)
{
return null;
}
var sb = new StringBuilder();
_writer = new JsonTextWriter(new StringWriter(sb, CultureInfo.InvariantCulture)) { CloseOutput = true };
foreach (var e in events)
{
this.WriteJsonEntry(e);
}
// Close the writer
_writer.Close();
_writer = null;
return sb.ToString();
}
示例5: GetJsonResult
private string GetJsonResult(int ParentID)
{
StringBuilder result = new StringBuilder();
StringWriter sw = new StringWriter(result);
JsonWriter writer = new JsonWriter(sw);
writer.Formatting = Formatting.None;
writer.WriteStartArray();
foreach (DataRow row in GetSubCategory(ParentID).Rows)
{
writer.WriteStartObject();
WriteJsonKeyValue(writer, "catename", row["catename"].ToString());
WriteJsonKeyValue(writer, "cateid", row["cateid"].ToString());
writer.WriteEndObject();
}
writer.WriteEndArray();
writer.Close();
return result.ToString();
}
示例6: GetJsonData
public string GetJsonData()
{
StringBuilder sb = new StringBuilder(100);
StringWriter sw = new StringWriter(sb);
JsonWriter js = new JsonWriter(sw);
js.WriteStartObject();
if (spOrderProduct != null)
{
js.WritePropertyName("opnum");
js.WriteValue(spOrderProduct.Quantity);
js.WritePropertyName("opsum");
js.WriteValue(spOrderProduct.ProductSum);
js.WritePropertyName("opscore");
js.WriteValue(spOrderProduct.TotalScore);
}
js.WritePropertyName("carttsum");
js.WriteValue(spCart.TotalSum);
js.WritePropertyName("cartpsum");
js.WriteValue(spCart.ProductSum);
js.WriteEndObject();
js.Close();
return sb.ToString();
}
示例7: OnGUI
//.........这里部分代码省略.........
reorderableList = new ReorderableList(charAbilities, typeof(int),
false, true, true, true);
reorderableList.drawElementCallback =
(Rect rect, int index, bool isActive, bool isFocused) => {
var element = reorderableList.list[index];
rect.y += 2;
reorderableList.list[index] = EditorGUI.IntField(
new Rect(rect.x, rect.y, 60, EditorGUIUtility.singleLineHeight),
(int)element);
};
}
reorderableList.DoLayoutList();
foreach (FieldInfo info in targetType.GetFields(flags))
{
Type fieldType = info.FieldType;
if (fieldType == typeof(int))
{
info.SetValue(tempChar, EditorGUILayout.IntField(info.Name, (int)info.GetValue(tempChar)));
}
else if (fieldType == typeof(string))
{
info.SetValue(tempChar, EditorGUILayout.TextField(info.Name, (string)info.GetValue(tempChar)));
}
else if (fieldType == typeof(float))
{
info.SetValue(tempChar, EditorGUILayout.FloatField(info.Name, (float)info.GetValue(tempChar)));
}
else if (fieldType == typeof(Character.Stats)) //struct
{
EditorGUILayout.Space();
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
if (tempStruct == null)
{
tempStruct = new Character.Stats();
info.SetValue(tempChar, (Character.Stats)tempStruct);
}
foreach (FieldInfo infoInStruct in fieldType.GetFields(flags))
{
Type fieldTypeInStruct = infoInStruct.FieldType;
if (fieldTypeInStruct == typeof(float))
{
infoInStruct.SetValue(tempStruct, EditorGUILayout.FloatField(infoInStruct.Name, (float)infoInStruct.GetValue(info.GetValue(tempChar)) ));
}
}
info.SetValue(tempChar, (Character.Stats)tempStruct);
EditorGUILayout.EndVertical();
EditorGUILayout.Space();
}
else if (fieldType == typeof(TasteToStats))//object
{
var dirPath = new DirectoryInfo("Assets/Scripts/Character/TasteTranslation");
FileInfo[] fileInfo = dirPath.GetFiles();
List<string> fileNames = new List<string>();
for (int i = 0; i < fileInfo.Length; i++)
{
if (!fileInfo[i].Name.Contains("meta") && !fileInfo[i].Name.Equals("TasteToStats.cs"))
{
fileNames.Add(fileInfo[i].Name);
}
}
tasteToStats = EditorGUILayout.Popup("Ability:", tasteToStats, fileNames.ToArray());
MonoScript derp = AssetDatabase.LoadAssetAtPath<MonoScript>("Assets/Scripts/Character/TasteTranslation/"+ fileNames[tasteToStats]);
info.SetValue(tempChar, Activator.CreateInstance(derp.GetClass()));
}
else if (fieldType == typeof(List<int>))
{
info.SetValue(tempChar, charAbilities);
}
}
EditorGUILayout.EndVertical();
if (GUILayout.Button("submit"))
{
textWriter = new StreamWriter(Application.dataPath + itemFileName);
jsonWriter = new JsonTextWriter(textWriter);
database.Add(tempChar);
String text = JsonConvert.SerializeObject(database, Formatting.Indented, new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Objects,
TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
});
textWriter.Write(text);
textWriter.Close();
textWriter.Dispose();
jsonWriter.Close();
tempChar = new Character();
tempStruct = null;
reorderableList = null;
charAbilities = new List<int>();
}
}
示例8: OnGUI
//.........这里部分代码省略.........
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
foreach (FieldInfo info in targetType.GetFields(flags))
{
Type fieldType = info.FieldType;
if (fieldType == typeof(int))
{
if (info.Name.Contains("id")){
info.SetValue(tempItem, database.Count);
EditorGUILayout.LabelField("ID of item", database.Count.ToString());
}
else
{
info.SetValue(tempItem, EditorGUILayout.IntField(info.Name, (int)info.GetValue(tempItem)));
}
}
else if (fieldType.IsEnum) {
if (info.GetValue(tempItem) == null)
info.SetValue(tempItem, Activator.CreateInstance(fieldType));
info.SetValue(tempItem, EditorGUILayout.EnumPopup(info.Name, (Enum)info.GetValue(tempItem)));
}
else if (fieldType == typeof(string))
{
string name = (String)info.GetValue(tempItem);
info.SetValue(tempItem, EditorGUILayout.TextField(info.Name, name));
}
else if (fieldType == typeof(float))
{
info.SetValue(tempItem, EditorGUILayout.FloatField(info.Name, (float)info.GetValue(tempItem)));
}
else if (fieldType.IsValueType && !fieldType.IsPrimitive && simpleFood) //struct
{
EditorGUILayout.Space();
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
if (fieldType == typeof(Food.Taste))
tempStruct = new Food.Taste();
foreach (FieldInfo infoInStruct in fieldType.GetFields(flags))
{
Type fieldTypeInStruct = infoInStruct.FieldType;
if (fieldTypeInStruct == typeof(int))
{
infoInStruct.SetValue(tempStruct, EditorGUILayout.IntField(infoInStruct.Name, (int)infoInStruct.GetValue(info.GetValue(tempItem))));
}
}
if (fieldType == typeof(Food.Taste))
{
info.SetValue(tempItem, (Food.Taste)tempStruct);
}
EditorGUILayout.EndVertical();
EditorGUILayout.Space();
}
else if (fieldType == typeof(GameObject))//object
{
abilityName = EditorGUILayout.TextField(info.Name, abilityName);
}
}
EditorGUILayout.EndVertical();
if (GUILayout.Button("submit"))
{
textWriter = new StreamWriter(Application.dataPath + itemFileName);
jsonWriter = new JsonTextWriter(textWriter);
database.Add(tempItem);
String text = JsonConvert.SerializeObject(database, Formatting.Indented, new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Objects,
TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
});
textWriter.Write(text);
textWriter.Close();
textWriter.Dispose();
jsonWriter.Close();
if (!simpleFood) {
tempRecipeStruct = new ComposedFood.recipe(listInputRecipe, tempItem.id);
textWriter = new StreamWriter(Application.dataPath + recipesFileName);
jsonWriter = new JsonTextWriter(textWriter);
recipes.Add((ComposedFood.recipe)tempRecipeStruct);
String recipeText = JsonConvert.SerializeObject(recipes, Formatting.Indented, new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Objects,
TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
});
textWriter.Write(recipeText);
textWriter.Close();
textWriter.Dispose();
jsonWriter.Close();
}
tempItem = null;
tempStruct = null;
reorderableList = null;
listInputRecipe = new List<int>();
}
}
示例9: GetEvaluation
private void GetEvaluation(HttpContext CurrentContext)
{
NewsEvaluationModelBll bll = new NewsEvaluationModelBll();
int NewsID = Convert.ToInt32(CurrentContext.Request["nid"]);
if (NewsID == 0)
{
CurrentContext.Response.Write(GetJsonResult(false, "参数错误!"));
return;
}
DataTable dt = bll.StatisticList(NewsID);
int Sum = 0;
foreach (DataRow row in dt.Rows) Sum += Convert.ToInt32(row["evaluationcount"]);
StringBuilder result = new StringBuilder();
StringWriter sw = new StringWriter(result);
JsonWriter writer = new JsonWriter(sw);
writer.Formatting = Formatting.Indented;
writer.WriteStartObject();
WriteJsonKeyValue(writer, "sum", Sum.ToString());
writer.WritePropertyName("items");
writer.WriteStartArray();
foreach (DataRow row in dt.Rows)
{
writer.WriteStartObject();
WriteJsonKeyValue(writer, "evaluation", row["evaluation"].ToString());
WriteJsonKeyValue(writer, "count", row["evaluationcount"].ToString());
WriteJsonKeyValue(writer, "percentage", Sum == 0 ? "0" : Convert.ToDouble((Convert.ToInt32(row["evaluationcount"]) * 100) / Sum).ToString("00"));
writer.WriteEndObject();
}
writer.WriteEndArray();
writer.WriteEndObject();
writer.Close();
CurrentContext.Response.Write("("+result.ToString()+")");
}
示例10: GetCommentList
private void GetCommentList(HttpContext CurrentContext)
{
CommentBll bll = new CommentBll();
int NewsID = Convert.ToInt32(CurrentContext.Request["nid"]);
if (NewsID == 0)
{
CurrentContext.Response.Write(GetJsonResult(false, "参数错误!"));
return;
}
DataTable dt = bll.GetList(AppType.News, NewsID);
StringBuilder result = new StringBuilder();
StringWriter sw = new StringWriter(result);
JsonWriter writer = new JsonWriter(sw);
writer.Formatting = Formatting.Indented;
writer.WriteStartArray();
foreach (DataRow row in dt.Rows)
{
writer.WriteStartObject();
WriteJsonKeyValue(writer, "userid", row["userid"].ToString());
WriteJsonKeyValue(writer, "content", row["content"].ToString());
WriteJsonKeyValue(writer, "createtime", Convert.ToDateTime(row["createtime"]).ToString("yyyy-MM-dd HH:mm:ss"));
writer.WriteEndObject();
}
writer.WriteEndArray();
writer.Close();
CurrentContext.Response.Write("(" + result.ToString() + ")");
}
示例11: OnGUI
void OnGUI()
{
Type targetType;
if (jsonSerializer == null)
{
Start();
}
var dirPath = new DirectoryInfo("Assets/Scripts/Abilities/");
FileInfo[] fileInfo = dirPath.GetFiles();
List<string> fileNames = new List<string>();
for(int i = 0; i < fileInfo.Length; i++)
{
if (!fileInfo[i].Name.Contains("meta") && !fileInfo[i].Name.Equals("Ability.cs"))
{
fileNames.Add(fileInfo[i].Name);
}
}
int newscript = EditorGUILayout.Popup("TasteTranslation:",chosenScript, fileNames.ToArray());
if(newscript != chosenScript)
{
chosenScript = newscript;
tempAbility = null;
}
abilityScript = AssetDatabase.LoadAssetAtPath<MonoScript>("Assets/Scripts/Abilities/"+ fileNames[chosenScript]);
targetType = abilityScript.GetClass();
if (tempAbility == null)
{
tempAbility = (Ability)Activator.CreateInstance(targetType);
}
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
EditorGUILayout.LabelField("id: ", database.Count.ToString());
foreach (FieldInfo info in targetType.GetFields(flags))
{
Type fieldType = info.FieldType;
if (fieldType == typeof(int))
{
info.SetValue(tempAbility, EditorGUILayout.IntField(info.Name, (int)info.GetValue(tempAbility)));
}else if(fieldType == typeof(string))
{
info.SetValue(tempAbility, EditorGUILayout.TextField(info.Name, (string)info.GetValue(tempAbility)));
}
else if (fieldType == typeof(bool))
{
info.SetValue(tempAbility, EditorGUILayout.Toggle(info.Name, (bool)info.GetValue(tempAbility)));
}
}
EditorGUILayout.EndVertical();
if (GUILayout.Button("submit"))
{
textWriter = new StreamWriter(Application.dataPath + itemFileName);
jsonWriter = new JsonTextWriter(textWriter);
database.Add(tempAbility);
String text = JsonConvert.SerializeObject(database, Formatting.Indented, new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Objects,
TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
});
textWriter.Write(text);
textWriter.Close();
textWriter.Dispose();
jsonWriter.Close();
tempAbility = null;
}
}
示例12: OnGUI
void OnGUI()
{
Type targetType;
charScript = AssetDatabase.LoadAssetAtPath<MonoScript>("Assets/Scripts/Enemies/Enemies.cs");
if (jsonSerializer == null)
{
Start();
}
targetType = charScript.GetClass();
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
EditorGUILayout.LabelField("id: ", database.Count.ToString());
if (reorderableList == null)
{
reorderableList = new ReorderableList(charAbilities, typeof(int),
false, true, true, true);
reorderableList.drawElementCallback =
(Rect rect, int index, bool isActive, bool isFocused) => {
var element = reorderableList.list[index];
rect.y += 2;
reorderableList.list[index] = EditorGUI.IntField(
new Rect(rect.x, rect.y, 60, EditorGUIUtility.singleLineHeight),
(int)element);
};
}
reorderableList.DoLayoutList();
foreach (FieldInfo info in targetType.GetFields(flags))
{
Type fieldType = info.FieldType;
if (fieldType == typeof(int))
{
info.SetValue(tempEnemy, EditorGUILayout.IntField(info.Name, (int)info.GetValue(tempEnemy)));
}
else if (fieldType == typeof(string))
{
info.SetValue(tempEnemy, EditorGUILayout.TextField(info.Name, (string)info.GetValue(tempEnemy)));
}
else if (fieldType == typeof(float))
{
info.SetValue(tempEnemy, EditorGUILayout.FloatField(info.Name, (float)info.GetValue(tempEnemy)));
}
else if (fieldType == typeof(Enemies.EnemyStats)) //struct
{
EditorGUILayout.Space();
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
if (tempStruct == null)
{
tempStruct = new Enemies.EnemyStats();
info.SetValue(tempEnemy, (Enemies.EnemyStats)tempStruct);
}
foreach (FieldInfo infoInStruct in fieldType.GetFields(flags))
{
Type fieldTypeInStruct = infoInStruct.FieldType;
if (fieldTypeInStruct == typeof(float))
{
infoInStruct.SetValue(tempStruct, EditorGUILayout.FloatField(infoInStruct.Name, (float)infoInStruct.GetValue(info.GetValue(tempEnemy)) ));
}
}
info.SetValue(tempEnemy, (Enemies.EnemyStats)tempStruct);
EditorGUILayout.EndVertical();
EditorGUILayout.Space();
}
else if (fieldType == typeof(List<int>))
{
info.SetValue(tempEnemy, charAbilities);
}
}
EditorGUILayout.EndVertical();
if (GUILayout.Button("submit"))
{
textWriter = new StreamWriter(Application.dataPath + itemFileName);
jsonWriter = new JsonTextWriter(textWriter);
database.Add(tempEnemy);
String text = JsonConvert.SerializeObject(database, Formatting.Indented, new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Objects,
TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
});
textWriter.Write(text);
textWriter.Close();
textWriter.Dispose();
jsonWriter.Close();
tempEnemy = new Enemies();
tempStruct = null;
reorderableList = null;
charAbilities = new List<int>();
}
}
示例13: GetMsgList
private string GetMsgList(HttpContext context)
{
MessageBll mbll = new MessageBll();
string[] roles = Roles.GetRolesForUser();
List<MessageModel> list = mbll.GetAllList(context.User.Identity.Name,roles,1);
StringBuilder result = new StringBuilder();
StringWriter sw = new StringWriter(result);
JsonWriter writer = new JsonWriter(sw);
writer.Formatting = Formatting.None;
//writer.WriteStartObject();
writer.WriteStartArray();
foreach (MessageModel item in list)
{
writer.WriteStartObject();
writer.WritePropertyName("msgid");
writer.WriteValue(item.MsgId);
writer.WritePropertyName("subject");
writer.WriteValue(item.Subject);
writer.WriteEndObject();
}
writer.WriteEndArray();
//writer.WriteEndObject();
writer.Close();
return result.ToString();
}
示例14: GetBrandJson
private string GetBrandJson(int ScenceID, int CategoryID)
{
StringBuilder result = new StringBuilder();
StringWriter sw = new StringWriter(result);
JsonWriter writer = new JsonWriter(sw);
writer.Formatting = Formatting.Indented;
DataTable dt = new CategoryConditionBll().GetConditionBrandList(ScenceID, CategoryID);
//new BrandCategoryRelationBll().GetCategoryBrandList(CategoryID);
writer.WriteStartArray();
foreach (DataRow row in dt.Rows)
{
writer.WriteStartObject();
WriteJsonKeyValue(writer, "brandid", row["brandid"].ToString());
WriteJsonKeyValue(writer, "brandname", row["brandname"].ToString());
writer.WriteEndObject();
}
writer.WriteEndArray();
writer.Close();
return result.ToString();
}
示例15: GetProductListJson
private string GetProductListJson(int ScenceID, int CategoryID,int FatherCategoryID, int BrandID, string ProductName,int OrderType)
{
bool HasSubCateogry;
DataTable dt = new CategoryConditionBll().GetCategoryProductList(ScenceID, CategoryID, FatherCategoryID, BrandID, ProductName,OrderType,out HasSubCateogry);
StringBuilder result = new StringBuilder();
StringWriter sw = new StringWriter(result);
JsonWriter writer = new JsonWriter(sw);
writer.Formatting = Formatting.Indented;
writer.WriteStartArray();
foreach (DataRow row in dt.Rows)
{
writer.WriteStartObject();
WriteJsonKeyValue(writer, "productid", row["productid"].ToString());
WriteJsonKeyValue(writer, "productname", row["productname"].ToString());
WriteJsonKeyValue(writer, "url", String.Format("/product-{0}.html", row["productid"]));
WriteJsonKeyValue(writer, "image", ProductMainImageRule.GetMainImageUrl(row["smallimage"].ToString()));
WriteJsonKeyValue(writer, "price", row["merchantprice"].ToString());
WriteJsonKeyValue(writer, "categoryid", HasSubCateogry ? row["cateid"].ToString() : "0");
writer.WriteEndObject();
}
writer.WriteEndArray();
writer.Close();
return result.ToString();
}