本文整理汇总了C#中Newtonsoft.Json.JsonTextWriter.WriteRawValue方法的典型用法代码示例。如果您正苦于以下问题:C# JsonTextWriter.WriteRawValue方法的具体用法?C# JsonTextWriter.WriteRawValue怎么用?C# JsonTextWriter.WriteRawValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.JsonTextWriter
的用法示例。
在下文中一共展示了JsonTextWriter.WriteRawValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Save
public void Save(IPersistable build)
{
using (var fileStream = new FileStream(Source, FileMode.Open, FileAccess.ReadWrite))
{
if (fileStream.Length > 0) //remove ] if we have content in file
{
fileStream.Seek(-1, SeekOrigin.End);
}
using (var sw = new StreamWriter(fileStream)) //add item to array
{
using (JsonWriter writer = new JsonTextWriter(sw))
{
if (sw.BaseStream.Position == 0) //begin array if this is first item
{
writer.WriteRawValue("[");
}
else //we are adding item to existing array
{
writer.WriteRawValue(",");
}
serializer.Serialize(writer, build.Data());
writer.WriteRawValue("]");
}
}
}
}
示例2: parameterFieldMapJson
/// <summary>
/// Convert parameter list to json object
/// </summary>
public static string parameterFieldMapJson(parameters parms, string ProjectID, string QueryID)
{
StringWriter sw = new StringWriter();
JsonTextWriter json = new JsonTextWriter(sw);
json.WriteStartObject();
json.WritePropertyName("results");
json.WriteStartArray();
json.WriteStartObject();
// ProjectID and QueryID
json.WritePropertyName("ProjectID");
json.WriteValue(ProjectID);
json.WritePropertyName("QueryID");
json.WriteValue(QueryID);
json.WritePropertyName("parameters");
json.WriteRawValue(JsonConvert.SerializeObject(parms));
json.WriteEndObject();
json.WriteEndArray();
json.WriteEndObject();
json.Flush();
sw.Flush();
return sw.ToString();
}
示例3: Serialize
public void Serialize(JsonWriter writer)
{
if (string.IsNullOrWhiteSpace(MimeType) || string.IsNullOrWhiteSpace(Content))
return;
var sb = new StringBuilder();
var sw = new StringWriter(sb);
using (JsonWriter jw = new JsonTextWriter(sw))
{
jw.WritePropertyName(MimeType);
jw.WriteStartObject();
if (!string.IsNullOrWhiteSpace(Content))
{
jw.WriteRawValue(Content);
}
jw.WriteEndObject();
if (jw.WriteState == WriteState.Error)
sb.Clear();
}
writer.WriteRawValue(sb.ToString());
}
示例4: StringWriter
void do确定_Click(object sender, EventArgs e)
{
var __sw = new StringWriter();
JsonWriter __writer = new JsonTextWriter(__sw);
__writer.WriteStartArray();
foreach (DataGridViewRow __行 in this.out值.Rows)
{
if (!__行.IsNewRow)
{
var __value = __行.Cells[0].Value == null ? "" : __行.Cells[0].Value.ToString();
if (_元数据 != null)
{
switch (_元数据.类型)
{
case "string":
case "字符串":
__writer.WriteValue(__value);
break;
default:
__writer.WriteRawValue(__value);
break;
}
}
else
{
__writer.WriteRawValue(__value);
}
}
}
__writer.WriteEndArray();
__writer.Flush();
_值 = __sw.GetStringBuilder().ToString();
this.DialogResult = DialogResult.OK;
}
示例5: ToJson
/// <summary>
/// Serializes <see cref="Graphic"/> into JSON string.
/// </summary>
/// <param name="graphic">graphic to serialize into JSON.</param>
/// <returns>string representation of the JSON object.</returns>
public static string ToJson(this Graphic graphic)
{
StringBuilder sb = new StringBuilder();
using (StringWriter sw = new StringWriter(sb))
{
using (JsonWriter jw = new JsonTextWriter(sw))
{
if (graphic.Geometry != null)
{
jw.WriteStartObject();
jw.WritePropertyName("geometry");
// Gets the JSON string representation of the Geometry.
jw.WriteRawValue(graphic.Geometry.ToJson());
jw.WriteEndObject();
}
if (graphic.Attributes.Count > 0)
{
jw.WriteStartObject();
foreach (var item in graphic.Attributes)
{
jw.WritePropertyName(item.Key);
jw.WriteValue(item.Value);
}
jw.WriteEndObject();
}
}
return sb.ToString();
}
}
示例6: AddEntry
public static void AddEntry(String displayName, String name, String id)
{
_catalog.configs[name] = "{\"displayName\":\""+displayName+"\",\"folder\":\"" + name + "\", \"id\":\"" + id + "\"}";
using (StreamWriter sw = new StreamWriter(_configDirectory + "catalog.json"))
{
using (JsonTextWriter jw = new JsonTextWriter(sw))
{
jw.WriteRawValue(JsonConvert.SerializeObject(_catalog));
}
}
}
示例7: GetOuterBoundaryMask
public HttpResponseMessage GetOuterBoundaryMask()
{
var stringBuilder = new StringBuilder();
var jsonTextWriter = new JsonTextWriter(new StringWriter(stringBuilder));
var outerBoundaryGeoJson = _geoService.GetOuterBoundaryMaskGeoJson();
jsonTextWriter.WriteRawValue(outerBoundaryGeoJson);
var response = this.Request.CreateResponse(HttpStatusCode.OK);
response.Content = new StringContent(stringBuilder.ToString(), Encoding.UTF8, "application/json");
return response;
}
示例8: WriteApi
internal string WriteApi(Uri basePath, string servicePath, Type serviceType, Stack<Type> typeStack)
{
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
using (JsonWriter writer = new JsonTextWriter(sw))
{
writer.WriteStartObject();
writer.WritePropertyName("apiVersion");
writer.WriteValue(serviceType.Assembly.GetName().Version.ToString());
writer.WritePropertyName("swaggerVersion");
writer.WriteValue(Globals.SWAGGER_VERSION);
writer.WritePropertyName("basePath");
writer.WriteValue(string.Format("{0}://{1}", basePath.Scheme, basePath.Authority));
writer.WritePropertyName("resourcePath");
writer.WriteValue(string.Format(servicePath));
writer.WritePropertyName("apis");
writer.WriteRawValue(WriteApis(_Mapper.FindMethods(servicePath, serviceType, typeStack)));
writer.WritePropertyName("models");
writer.WriteRawValue(WriteModels(typeStack));
}
return sb.ToString();
}
示例9: GetBoroughBoundaries
public HttpResponseMessage GetBoroughBoundaries()
{
var stringBuilder = new StringBuilder();
var jsonTextWriter = new JsonTextWriter(new StringWriter(stringBuilder));
jsonTextWriter.WriteStartObject();
foreach (var boroughBoundary in _geoService.GetBoroughBoundariesGeoJson())
{
jsonTextWriter.WritePropertyName(boroughBoundary.Key);
jsonTextWriter.WriteRawValue(boroughBoundary.Value);
}
jsonTextWriter.WriteEndObject();
var response = this.Request.CreateResponse(HttpStatusCode.OK);
response.Content = new StringContent(stringBuilder.ToString(), Encoding.UTF8, "application/json");
return response;
}
示例10: ToJson
internal override string ToJson()
{
StringBuilder sb = new StringBuilder();
using (StringWriter sw = new StringWriter(sb))
{
using (JsonWriter jw = new JsonTextWriter(sw))
{
jw.WriteStartObject();
if (Graphics != null && Graphics.Count > 0)
{
jw.WritePropertyName("featureCollection");
jw.WriteRawValue(new FeatureSet(Graphics).ToJson());
}
jw.WriteEndObject();
}
}
return sb.ToString();
}
示例11: ToJsonString
public string ToJsonString()
{
var sb = new StringBuilder();
using(var sw = new StringWriter(sb))
using(JsonWriter jw = new JsonTextWriter(sw))
{
jw.WriteStartArray();
jw.WriteValue(FunctionName);
jw.WriteStartArray();
Argument.ForEach(a => jw.WriteRawValue(a.ToString()));
jw.WriteEndArray();
jw.WriteEndArray();
}
return sb.ToString();
}
示例12: ToJson2
/// <summary>
/// Extension method for serializing <see cref="Envelope"/> into JSON object
/// as expected in context parameter of <see cref="AggregatePointsParameter"/>
/// </summary>
/// <param name="envelope"></param>
/// <returns></returns>
public static string ToJson2(this Envelope envelope)
{
StringBuilder sb = new StringBuilder();
using (StringWriter sw = new StringWriter(sb))
{
using (JsonWriter jw = new JsonTextWriter(sw))
{
jw.WriteStartObject();
jw.WritePropertyName("outExtent");
jw.WriteRawValue(envelope.ToJson());
if (envelope.SpatialReference != null && envelope.SpatialReference.WKID > 0)
{
jw.WritePropertyName("outSR");
jw.WriteValue(envelope.SpatialReference.WKID.ToString(CultureInfo.InvariantCulture));
}
jw.WriteEndObject();
}
}
return sb.ToString();
}
示例13: WriteType
internal string WriteType(Type t, Stack<Type> typeStack)
{
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
using (JsonWriter writer = new JsonTextWriter(sw))
{
writer.WriteStartObject();
var idValue = Helpers.GetDataContractNamePropertyValue(t) ?? t.FullName;
writer.WritePropertyName("id");
writer.WriteValue(idValue);
writer.WritePropertyName("properties");
writer.WriteRawValue(WriteProperties(t, typeStack));
}
return sb.ToString();
}
示例14: WriteRawValue
public void WriteRawValue()
{
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
using (JsonWriter jsonWriter = new JsonTextWriter(sw))
{
int i = 0;
string rawJson = "[1,2]";
jsonWriter.WriteStartObject();
while (i < 3)
{
jsonWriter.WritePropertyName("d" + i);
jsonWriter.WriteRawValue(rawJson);
i++;
}
jsonWriter.WriteEndObject();
}
Assert.AreEqual(@"{""d0"":[1,2],""d1"":[1,2],""d2"":[1,2]}", sb.ToString());
}
示例15: JsonTextWriter
/// <summary>
/// Serializes only the necessary components of the <see cref="PersistentResponse"/> to JSON
/// using Json.NET's JsonTextWriter to improve performance.
/// </summary>
/// <param name="writer">The <see cref="System.IO.TextWriter"/> that receives the JSON serialization.</param>
void IJsonWritable.WriteJson(TextWriter writer)
{
var jsonWriter = new JsonTextWriter(writer);
jsonWriter.WriteStartObject();
jsonWriter.WritePropertyName("C");
jsonWriter.WriteValue(MessageId);
if (Disconnect)
{
jsonWriter.WritePropertyName("D");
jsonWriter.WriteValue(1);
}
if (TimedOut)
{
jsonWriter.WritePropertyName("T");
jsonWriter.WriteValue(1);
}
if (GroupsToken != null)
{
jsonWriter.WritePropertyName("G");
jsonWriter.WriteValue(GroupsToken);
}
if (LongPollDelay.HasValue)
{
jsonWriter.WritePropertyName("L");
jsonWriter.WriteValue(LongPollDelay.Value);
}
jsonWriter.WritePropertyName("M");
jsonWriter.WriteStartArray();
Messages.Enumerate(m => !m.IsCommand && !ExcludeFilter(m),
m => jsonWriter.WriteRawValue(m.Value));
jsonWriter.WriteEndArray();
jsonWriter.WriteEndObject();
}