Note that there are some explanatory texts on larger screens.

plurals
  1. POPartially deserializing a JSON string with multiple roots
    primarykey
    data
    text
    <p>I am coding a C# version 4 application that consumes REST web services. Those web services are written with ASP.NET MVC RESTful web service approach. Half of those web service methods return JSON strings with <b>multiple roots</b> (please see the sample JSON data below). However, for a specific JSON response (please see one below), I would like partially deserialize a <b>multiple-root</b> JSON response string into an Device object (e.g. belonging to Device class) which I am interested in instead of all of the data response. </p> <p>I know how to use C# .NET library or JSON.net codes to deserialize a JSON string that has only one root. But I am not sure how to do with multiple-root JSON data. Please advice. Thank you. </p> <p>For instance, with the following JSON response, I want to retrieve data for “device” object (instantiated from Device class), and <b>ignore</b> “version_info” and “SKU_info” data.</p> <p>The following JSON response has 3 roots: "version_info", "SKU_info", and "device":</p> <pre><code>{ “version_info” : { “version” : “1.0”, “owner_id” : 237}, “SKU_info” : {“id” : 1928399, “active”: true}, “device” : { “id”: 7732, “name” : “desktop computer ”, “parent_device_id”: 2982, “sub_devices”: [ {“id”: 7733, “name”: “fan”, “quantity” : 1 }, {“id”: 7734, “name”: “memory chip”, “quantity” : 4 }, {“id”: 7735, “name”: “CPU”, “quantity” : 1 }, {“id”: 7736, “name”: “hard disk”, “quantity” : 2 }, ], “user_id” : 864 } } </code></pre> <p>And my csutom “Device” and "SubDevice" classes:</p> <pre><code>public class Device { public long Id; public string Name; public long ParentDeviceId; public List&lt;SubDevice&gt; Subdevices; public int UserId; } public class SubDevice { public long Id; public string Name; public int Quantity; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    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