本文整理汇总了C#中Newtonsoft.Json.JsonTextWriter.WriteWhitespace方法的典型用法代码示例。如果您正苦于以下问题:C# JsonTextWriter.WriteWhitespace方法的具体用法?C# JsonTextWriter.WriteWhitespace怎么用?C# JsonTextWriter.WriteWhitespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.JsonTextWriter
的用法示例。
在下文中一共展示了JsonTextWriter.WriteWhitespace方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteRawInStart
public void WriteRawInStart()
{
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
using (JsonWriter jsonWriter = new JsonTextWriter(sw))
{
jsonWriter.Formatting = Formatting.Indented;
jsonWriter.FloatFormatHandling = FloatFormatHandling.Symbol;
jsonWriter.WriteRaw("[1,2,3,4,5]");
jsonWriter.WriteWhitespace(" ");
jsonWriter.WriteStartArray();
jsonWriter.WriteValue(double.NaN);
jsonWriter.WriteEndArray();
}
string expected = @"[1,2,3,4,5] [
NaN
]";
string result = sb.ToString();
Assert.AreEqual(expected, result);
}
示例2: SaveAnim
public void SaveAnim(string name)
{
if (!Directory.Exists("blueprints\\anim"))
{ Directory.CreateDirectory("blueprints\\anim"); }
FileStream fs = File.Open("blueprints\\anim\\" + name + ".json", FileMode.Create);
StreamWriter sw = new StreamWriter(fs);
JsonTextWriter jw = new JsonTextWriter(sw);
jw.Formatting = Formatting.Indented;
jw.WriteStartObject();
//anim
jw.WritePropertyName("animations");
jw.WriteStartArray();
foreach (Animation a in anims)
{
jw.WriteStartObject();
jw.WritePropertyName("name");
jw.WriteValue(a.name);
jw.WritePropertyName("speed");
jw.WriteValue(a.speed);
jw.WritePropertyName("loop");
jw.WriteValue(a.loopback);
jw.WritePropertyName("frames");
jw.WriteValue(a.frames.Count);
//collision
jw.WritePropertyName("collisionVolumes");
jw.WriteStartArray();
for (int i = 0; i < a.frames.Count; i++)
{
if (a.collision[i].Count > 0)
{
jw.WriteStartObject();
jw.WritePropertyName("volumes");
jw.WriteStartArray();
foreach (CollisionList cl in a.collision[i])
{
jw.WriteStartObject();
jw.WritePropertyName("physical");
jw.WriteValue(cl.Physical);
jw.WritePropertyName("centerX");
jw.WriteValue(a.frames[i].Width / 2);
jw.WritePropertyName("centerY");
jw.WriteValue(a.frames[i].Height / 2);
jw.WritePropertyName("xpoints");
jw.WriteStartArray();
foreach (CollisionPoint p in cl.Nodes)
{
jw.WriteValue(p.X - (a.frames[i].Width / 2));
}
jw.WriteEnd();
jw.WritePropertyName("ypoints");
jw.WriteStartArray();
foreach (CollisionPoint p in cl.Nodes)
{
jw.WriteValue(p.Y - (a.frames[i].Height / 2));
}
jw.WriteEnd();
jw.WriteEnd();
}
jw.WriteEnd();
jw.WriteEnd();
}
else
{
jw.WriteWhitespace("");
}
}
jw.WriteEnd();
// end anim
jw.WriteEnd();
}
jw.WriteEnd();
jw.WriteEnd();
jw.Close();
if (!Directory.Exists("images\\anim"))
{ Directory.CreateDirectory("images\\anim"); }
if (!Directory.Exists("images\\anim\\" + name))
{ Directory.CreateDirectory("images\\anim\\" + name); }
foreach (Animation a in anims)
{
if (!Directory.Exists("images\\anim\\" + name + "\\" + a.name))
{ Directory.CreateDirectory("images\\anim\\" + name + "\\" + a.name); }
int frameNum = 0;
foreach (Texture2D t in a.frames)
{
Stream s = File.OpenWrite("images\\anim\\" + name + "\\" + a.name + "\\" + frameNum + ".png");
t.SaveAsPng(s, t.Width, t.Height);
s.Close();
frameNum++;
}
}
}
示例3: TrStmtList
void TrStmtList(List<Statement/*!*/>/*!*/ stmts)
{
Contract.Requires(cce.NonNullElements(stmts));
List<LocalVariable> AllDecls = new List<LocalVariable>();
using (WriteArray()) {
j.WriteValue(KremlinAst.ESequence);
using (WriteArray()) {
WriteEUnit(); // in case the statement list is empty
foreach (Statement ss in stmts) {
// JsonTextWriter is forward-only, but after calling TrStmt() we may need
// to go back and inject new ELet statements to introduce temp variables.
// So call TrStmt() once to generate code to a throw-away MemoryStream,
// but remember what temps need to be introduced. Then introduce them
// and call TrStmt() once more, to generate the actual Json.
JsonTextWriter oldj = j;
VariableTracker oldtracker = VarTracker.Clone();
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
JsonTextWriter newj = new JsonTextWriter(sw);
newj.Formatting = oldj.Formatting;
newj.Indentation = oldj.Indentation;
j = newj;
var oldVarDeclsList = varDeclsList;
varDeclsList = new List<LocalVariable>();
TrStmt(ss);
j = oldj;
VarTracker = oldtracker;
var decls = varDeclsList; // Grab the set of just-declared variables generated by the first TrStmt() pass
varDeclsList = null; // Switch modes for next TrStmt() pass
AllDecls.AddRange(decls); // Accumulate the set of all variables this stmt list has generated
foreach (var l in decls) {
// ELet v in { Stmt
j.WriteStartArray();
j.WriteValue(KremlinAst.ELet);
j.WriteStartArray();
WriteBinder(l, l.Name, true); // lident
WriteDefaultValue(l.Type); // = default
VarTracker.Push(l);
// "in" is the contents that follow
j.WriteStartArray();
j.WriteValue(KremlinAst.ESequence);
j.WriteStartArray();
WriteEUnit();
}
newj.Close();
string RawJson = sb.ToString();
if (RawJson != "") {
j.WriteRaw(",");
j.WriteWhitespace("\n");
j.WriteRaw(RawJson); // Now paste the JSON
}
if (ss.Labels != null) {
// bugbug: these appear to be used to support "Break" statements.
j.WriteComment("Labels are unsupported: " + ss.Labels.Data.AssignUniqueId("after_", idGenerator));
}
varDeclsList = oldVarDeclsList;
}
// Now that all statements in the list have been generated, close out the nested ELets generated above
AllDecls.Reverse();
foreach (var l in AllDecls) {
VarTracker.Pop(l);
j.WriteEndArray(); // Closing out the expr list in the ESequence
j.WriteEndArray(); // Closing out the array aboce ESequence
j.WriteEndArray(); // Closing out the list of binder * expr * expr
j.WriteEndArray(); // Closing out the array above ELet
}
}
}
}
示例4: SaveToFile
public bool SaveToFile(string filename)
{
try
{
using (StreamWriter sr = new StreamWriter(filename))
{
using (JsonTextWriter jr = new JsonTextWriter(sr))
{
jr.WriteRaw("[");
jr.WriteStartObject();
jr.WritePropertyName("FlightType"); jr.WriteValue("V1");
jr.WritePropertyName("Date"); jr.WriteValue(DateTime.Now.ToString());
jr.WriteEndObject();
jr.WriteRaw(",");
jr.WriteWhitespace(Environment.NewLine);
for (int i = 0; i < entries.Count; i++)
{
jr.WriteStartObject();
jr.WritePropertyName("T"); jr.WriteValue(entries[i].offsettime);
if (entries[i].IsPosSet)
{
jr.WritePropertyName("Pos"); jr.WriteStartArray(); jr.WriteValue(entries[i].pos.X);
jr.WriteValue(entries[i].pos.Y); jr.WriteValue(entries[i].pos.Z); jr.WriteEndArray();
if (entries[i].timetofly != 0)
{
jr.WritePropertyName("FlyTime"); jr.WriteValue(entries[i].timetofly);
}
}
if (entries[i].IsDirSet)
{
jr.WritePropertyName("Dir"); jr.WriteStartArray(); jr.WriteValue(entries[i].dir.X);
jr.WriteValue(entries[i].dir.Y); jr.WriteValue(entries[i].dir.Z); jr.WriteEndArray();
if (entries[i].timetopan != 0)
{
jr.WritePropertyName("PanTime"); jr.WriteValue(entries[i].timetopan);
}
}
if (entries[i].IsZoomSet)
{
jr.WritePropertyName("Z"); jr.WriteValue(entries[i].zoom);
if (entries[i].timetozoom != 0)
{
jr.WritePropertyName("ZTime"); jr.WriteValue(entries[i].timetozoom);
}
}
if ( entries[i].IsMessageSet )
{
jr.WritePropertyName("Msg"); jr.WriteValue(entries[i].message);
if (entries[i].messagetime != 0)
{
jr.WritePropertyName("MsgTime"); jr.WriteValue(entries[i].messagetime);
}
}
jr.WriteEndObject();
if ( i < entries.Count-1 )
jr.WriteRaw(",");
jr.WriteWhitespace(Environment.NewLine);
}
jr.WriteRaw("]");
}
}
return true;
}
catch { }
return false;
}