本文整理汇总了C#中Newtonsoft.Json.Linq.JObject.CreateWriter方法的典型用法代码示例。如果您正苦于以下问题:C# JObject.CreateWriter方法的具体用法?C# JObject.CreateWriter怎么用?C# JObject.CreateWriter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.Linq.JObject
的用法示例。
在下文中一共展示了JObject.CreateWriter方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Example
public void Example()
{
#region Usage
JObject o = new JObject
{
{"name1", "value1"},
{"name2", "value2"}
};
JsonWriter writer = o.CreateWriter();
writer.WritePropertyName("name3");
writer.WriteStartArray();
writer.WriteValue(1);
writer.WriteValue(2);
writer.WriteEndArray();
Console.WriteLine(o.ToString());
// {
// "name1": "value1",
// "name2": "value2",
// "name3": [
// 1,
// 2
// ]
// }
#endregion
}
示例2: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var val = (IColorEffect) value;
var nameProp = new JProperty("name", val.Name);
var jobj = new JObject(nameProp);
var objWriter = jobj.CreateWriter();
if (value is FixedColor)
{
objWriter.WritePropertyName("color");
serializer.Serialize(objWriter, ((FixedColor) val).Colors[0]);
}
if (value is ImageEffect)
{
objWriter.WritePropertyName("imageName");
objWriter.WriteValue(((ImageEffect)value).ImageName);
objWriter.WritePropertyName("width");
objWriter.WriteValue(((ImageEffect)value).Width);
}
objWriter.WritePropertyName("colors");
//serializer.Serialize(objWriter, ((ColorFade)val).Colors.Select(c => new JValue(c)));
serializer.Serialize(objWriter, val.Colors);
jobj.WriteTo(writer);
}
示例3: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var pattern = (Pattern) value;
var jobj = new JObject(new JProperty("name", pattern.Name),
new JProperty("groups", new JArray(pattern.Groups.Select(g => new JValue(g)))),
new JProperty("effectName", pattern.EffectName),
new JProperty("priority", pattern.Priority));
var jwriter = jobj.CreateWriter();
jwriter.WritePropertyName("effectProperties");
serializer.Serialize(jwriter, pattern.EffectProperties.Properties);
jobj.WriteTo(writer, serializer.Converters.ToArray());
}
示例4: Store
//.........这里部分代码省略.........
new SqlParameter("hash", hash)).First();
}
var contents = new List<AdContent>();
var content = new AdContent
{
Type = AdContent.ContentType.AllowCommercial.ToString(),
Value = ad.GetTokenValue("Contents>AllowCommercial").FirstOrDefault()
};
contents.Add(content);
content = new AdContent
{
Type = AdContent.ContentType.ContactUrl.ToString(),
Value = ad.GetTokenValue("Contents>ContactUrl").FirstOrDefault()
};
contents.Add(content);
content = new AdContent
{
Type = AdContent.ContentType.Description.ToString(),
Value = ad.GetTokenValue("Contents>Description").FirstOrDefault()
};
contents.Add(content);
content = new AdContent
{
Type = AdContent.ContentType.Latitude.ToString(),
Value = ad.GetTokenValue("Contents>Latitude").FirstOrDefault()
};
contents.Add(content);
content = new AdContent
{
Type = AdContent.ContentType.Longitude.ToString(),
Value = ad.GetTokenValue("Contents>Longitude").FirstOrDefault()
};
contents.Add(content);
content = new AdContent
{
Type = AdContent.ContentType.Name.ToString(),
Value = ad.GetTokenValue("Contents>Name").FirstOrDefault()
};
contents.Add(content);
content = new AdContent
{
Type = AdContent.ContentType.Phone.ToString(),
Value = ad.GetTokenValue("Contents>Phone").FirstOrDefault()
};
contents.Add(content);
content = new AdContent
{
Type = AdContent.ContentType.Place.ToString(),
Value = ad.GetTokenValue("Contents>Place").FirstOrDefault()
};
contents.Add(content);
content = new AdContent
{
Type = AdContent.ContentType.Price.ToString(),
Value = ad.GetTokenValue("Contents>Price").FirstOrDefault()
};
contents.Add(content);
foreach (var param in ad.GetTokenValue("Contents>Param"))
{
content = new AdContent { Type = AdContent.ContentType.Param.ToString(), Value = param };
contents.Add(content);
}
foreach (var picture in ad.GetTokenValue("Contents>PictureUrl"))
{
content = new AdContent { Type = AdContent.ContentType.PictureUrl.ToString(), Value = picture };
contents.Add(content);
}
using (var db = new ApplicationDbContext())
{
foreach (var adContent in contents.Where(c => c.Value != null))
{
db.Database.ExecuteSqlCommand("exec AddAdContent @ad_id, @type, @value",
new SqlParameter("ad_id", (int)adId),
new SqlParameter("type", adContent.Type),
new SqlParameter("value", adContent.Value));
}
}
using (var writer = ad.CreateWriter())
{
writer.WritePropertyName("Id");
writer.WriteValue(adId);
writer.WritePropertyName("SearchId");
writer.WriteValue(this.searchId);
}
return true;
}