public Export ( object value, JsonWriter writer ) : void | ||
value | object | |
writer | JsonWriter | |
리턴 | void |
public void Export(ExportContext context, Jayrock.Json.JsonWriter writer) { //"from":"Device-1","message":"JUAN" writer.WriteStartObject(); writer.WriteMember("from"); context.Export(From, writer); writer.WriteMember("message"); context.Export(Message, writer); writer.WriteEndObject(); }
public void Export(ExportContext context, JsonWriter writer, object source) { if (context == null) { throw new ArgumentNullException("context"); } if (writer == null) { throw new ArgumentNullException("writer"); } if (source == null) { throw new ArgumentNullException("source"); } object value = _property.GetValue(source); if (JsonNull.LogicallyEquals(value) || value.Equals(_defaultValue)) { return; } writer.WriteMember(_property.Name); context.Export(value, writer); }
public void ExportJsonNullValue() { ExportContext context = new ExportContext(); JsonRecorder writer = new JsonRecorder(); context.Export(JsonNull.Value, writer); JsonReader reader = writer.CreatePlayer(); reader.ReadNull(); Assert.IsTrue(reader.EOF); }
public static void Export(object value, JsonWriter writer) { if (writer == null) { throw new ArgumentNullException("writer"); } ExportContext exportContext = new ExportContext(); exportContext.Export(value, writer); }
public void ExportJsonNullValue() { ExportContext context = new ExportContext(); JsonRecorder writer = new JsonRecorder(); context.Export(JsonNull.Value, writer); JsonReader reader = writer.CreatePlayer(); reader.ReadNull(); Assert.IsTrue(reader.EOF); }
static void Main(string[] args) { //need a string builder ExportContext exportCtx = new ExportContext(); exportCtx.Register(new GrailsDateTimeExporter()); WebClient client = new WebClient(); AppStatus status; string command; while ((command = Console.ReadLine()) != "q") { status = new AppStatus() { LastUpdate = DateTime.Now, Message = "Hello .NET", RunningOK = true }; StringBuilder jsonString = new StringBuilder(); StringWriter writer = new StringWriter(jsonString); exportCtx.Export(status, new JsonTextWriter(writer)); byte[] data = Encoding.ASCII.GetBytes(jsonString.ToString()); client.UploadData(AppStatus_URI, data); Console.WriteLine(">>>>>Response Received>>>>>>"); } }
protected virtual void WriteResponse(object response, TextWriter output) { if (response == null) throw new ArgumentNullException("response"); if (output == null) throw new ArgumentNullException("output"); JsonWriter writer = (JsonWriter) _serviceProvider.GetService(typeof(JsonWriter)); if (writer == null) writer = new JsonTextWriter(output); ExportContext exportContext = new ExportContext(); exportContext.Export(response, writer); }
public void Export(ExportContext context, JsonWriter writer, object source) { if (context == null) throw new ArgumentNullException("context"); if (writer == null) throw new ArgumentNullException("writer"); if (source == null) throw new ArgumentNullException("source"); object value = _property.GetValue(source); if (JsonNull.LogicallyEquals(value) || value.Equals(_defaultValue)) return; writer.WriteMember(_property.Name); context.Export(value, writer); }
protected virtual void Export(ExportContext context, JsonWriter writer) { if (context == null) throw new ArgumentNullException("context"); if (writer == null) throw new ArgumentNullException("writer"); writer.WriteStartObject(); foreach (string name in NameIndexList) { writer.WriteMember(name); context.Export(InnerHashtable[name], writer); } writer.WriteEndObject(); }
protected virtual void Export(ExportContext context, JsonWriter writer) { if (context == null) throw new ArgumentNullException("context"); if (writer == null) throw new ArgumentNullException("writer"); writer.WriteStartArray(); foreach (object value in this) context.Export(value, writer); writer.WriteEndArray(); }
public void Export(ExportContext context, object value, Jayrock.Json.JsonWriter writer) { context.Export(value, writer); }
private static void Run() { ImportContext impctx = new ImportContext(); // // Import a strongly-typed collection of integers... // impctx.Register(new ListImporter<int>()); List<int> numbers = (List<int>) impctx.Import(typeof(List<int>), JsonText.CreateReader("[ 1, 2, 3 ]")); numbers.ForEach(Console.WriteLine); Console.WriteLine(); // // Import a Shape object containing a strongly-typed collection of // Point objects. // impctx.Register(new ListImporter<Point>()); Shape shape = (Shape) impctx.Import(typeof(Shape), JsonText.CreateReader(@"{ name: 'square', points: [ { x: 10, y: 10 }, { x: 20, y: 10 }, { x: 20, y: 20 }, { x: 10, y: 20 } ] }")); JsonConvert.Export(shape, CreatePrettyWriter(Console.Out)); Console.WriteLine(); // // Import CookieCollection using duck-typing. In other words, // as long as CookieCollection walks and quacks like a // collection of Cookie elements then it's good enough for // DuckCollectionImporter. DuckCollectionImporter can infer // that CookieCollection contains Cookie elements. // impctx.Register(new DuckCollectionImporter(typeof(CookieCollection))); const string cookiesText = @"[ { name: 'one', value: 1, expires: '2099-01-02' }, { name: 'two', value: 2, expires: '2088-03-04' }, { name: 'three', value: 3, expires: '2077-05-06' } ]"; CookieCollection cookies = (CookieCollection) impctx.Import(typeof(CookieCollection), JsonText.CreateReader(cookiesText)); JsonConvert.Export(cookies, CreatePrettyWriter(Console.Out)); Console.WriteLine(); // // Now repeat, but replace with a new CookieCollection importer // that is identical in behavior but based on generics. Here, // the difference is that DuckCollectionImporter<,> does not // have to guess the element type as it is provided as a type // argument. // impctx.Register(new DuckCollectionImporter<CookieCollection, Cookie>()); cookies = (CookieCollection)impctx.Import(typeof(CookieCollection), JsonText.CreateReader(cookiesText)); JsonConvert.Export(cookies, CreatePrettyWriter(Console.Out)); Console.WriteLine(); // // Those Cookie objects have a lot of properties. Say our JSON // text only needs a subset. Here, we register an exporter that // provides a custom view of the type. We only expose the name, // value and expiration time. What's more, we rename the // Expires property so that it appears as "expiration" in JSON. // ExportContext expctx = new ExportContext(); JsonType. BuildFor(typeof(Cookie)). AddProperty("Name"). AddProperty("Value"). AddProperty("Expires").As("expiration"). Register(expctx); expctx.Export(cookies, CreatePrettyWriter(Console.Out)); Console.WriteLine(); }
/// <summary> /// The export. /// </summary> /// <param name="context"> /// The context. /// </param> /// <param name="value"> /// The value. /// </param> /// <param name="writer"> /// The writer. /// </param> public void Export(ExportContext context, object value, JsonWriter writer) { writer.WriteStartObject(); writer.WriteMember("Critter"); var critter = (Critter)value; writer.WriteStartObject(); if (exportType > ExportType.Expanded) { writer.WriteMember("Age"); writer.WriteNumber(critter.Age); writer.WriteMember("N"); writer.WriteNumber(critter.N); } writer.WriteMember("Rank"); writer.WriteNumber(critter.Rank); writer.WriteMember("Fitness"); writer.WriteStartObject(); int i = 0; foreach (var n in Enum.GetNames(typeof(FitnessParameter))) { writer.WriteMember(n); writer.WriteNumber(critter.Fitness[i++]); } writer.WriteEndObject(); // writer.WriteMember("Fitness"); // context.Export(critter.Fitness,writer); if (exportType > ExportType.Summary) { writer.WriteMember("Route"); writer.WriteStartArray(); foreach (var node in critter.Route) { writer.WriteNumber(node.Node.Id); } writer.WriteEndArray(); } writer.WriteMember("Legs"); writer.WriteStartArray(); foreach (var leg in critter.Fitness.JourneyLegs) { writer.WriteStartObject(); if (exportType > ExportType.Summary) { writer.WriteMember("Start"); writer.WriteNumber(leg.Origin.Id); writer.WriteMember("End"); writer.WriteNumber(leg.Destination.Id); writer.WriteMember("Route"); writer.WriteString(leg.RouteId1); } if (exportType > ExportType.Simple) { writer.WriteMember("StartLocation"); writer.WriteStartObject(); writer.WriteMember("Lat"); writer.WriteNumber(leg.Origin.Latitude); writer.WriteMember("Long"); writer.WriteNumber(leg.Origin.Longitude); writer.WriteEndObject(); writer.WriteMember("EndLocation"); writer.WriteStartObject(); writer.WriteMember("Lat"); writer.WriteNumber(leg.Destination.Latitude); writer.WriteMember("Long"); writer.WriteNumber(leg.Destination.Longitude); writer.WriteEndObject(); } writer.WriteMember("Mode"); writer.WriteString(leg.TransportMode.ToString()); writer.WriteMember("TotalTime"); context.Export(leg.TotalTime, writer); writer.WriteMember("DepartTime"); context.Export(leg.DepartureTime, writer); writer.WriteMember("OriginName"); writer.WriteString(leg.Origin.StopSpecName); writer.WriteEndObject(); } writer.WriteEndArray(); writer.WriteEndObject(); writer.WriteEndObject(); }