Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Because you have a class representing the data coming back from the service, if you don't mind returning the entire class properties to your client, then simply use one of the many json serializers out there. Start here: <a href="http://www.nuget.org/packages?q=json" rel="nofollow">http://www.nuget.org/packages?q=json</a></p> <p>If you want to reduce the number of fields that get serialized, then create your own class, convert the service object to your own class, and then serialize that using the same techniques.</p> <p>Here is the Json.Net documentation showing how to serialize. <a href="http://james.newtonking.com/json/help/index.html" rel="nofollow">http://james.newtonking.com/json/help/index.html</a></p> <p><strong>Update: Show conversion and serialization</strong></p> <p>Note: Uses ServiceStack serializer <a href="https://github.com/ServiceStack/ServiceStack.Text" rel="nofollow">https://github.com/ServiceStack/ServiceStack.Text</a></p> <pre><code>// get data from the service var serviceData = new List&lt;ServiceObject&gt; { new ServiceObject { name = "one", soldTo = "00000123", city = "sydney", state = "nsw", addressLine1 = "king st", addressLine2 = "", zip = "0123", country = "australia" }, new ServiceObject { name = "two", soldTo = "00000456", city = "melbourne", state = "vic", addressLine1 = "william st", addressLine2 = "", zip = "0456", country = "australia" }, new ServiceObject { name = "three", soldTo = "00000789", city = "adelaide", state = "sa", addressLine1 = "county cres", addressLine2 = "", zip = "0789", country = "australia" } }; // convert it to what you want to return var jsData = (from row in serviceData select new JsObject { name = row.name, soldTo = row.soldTo, address = new JsAddress { line1 = row.addressLine1, line2 = row.addressLine2, postCode = row.zip, state = row.state, country = row.country } }).ToList(); // turn it into a json string var json = JsonSerializer.SerializeToString(jsData); // this will spit out the result when using Linqpad json.Dump("json"); } class ServiceObject { public string name { get; set; } public string soldTo { get; set; } public string city { get; set; } public string state { get; set; } public string addressLine1 { get; set; } public string addressLine2 { get; set; } public string zip { get; set; } public string country { get; set; } } class JsObject { public string name { get; set; } public string soldTo { get; set; } public JsAddress address { get; set; } } class JsAddress { public string line1 { get; set; } public string line2 { get; set; } public string state { get; set; } public string postCode { get; set; } public string country { get; set; } </code></pre> <p>Cheers, Aaron</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload