Note that there are some explanatory texts on larger screens.

plurals
  1. POApproach for parsing json string with different type of objects
    primarykey
    data
    text
    <p>I have following json string </p> <pre><code>{ "serverTime": "2013-08-12 02:45:55,558", "data": [{ "key1": 1, "result": { "sample1": [""], "sample2": "test2" } },{ "key1": 1, "result": { "sample3": [""], "sample4": "test2" } }] } </code></pre> <p>Using <a href="http://json2csharp.com/" rel="nofollow">JSONTOC#</a></p> <p>Following classes are generated.</p> <pre><code>public class Result { public List&lt;string&gt; sample1 { get; set; } public string sample2 { get; set; } public List&lt;string&gt; sample3 { get; set; } public string sample4 { get; set; } } public class Datum { public int key1 { get; set; } public Result result { get; set; } } public class RootObject { public string serverTime { get; set; } public List&lt;Datum&gt; data { get; set; } } </code></pre> <p>As one can see the tool has generated <strong>Result</strong> class with all the possible properties.</p> <p>I am trying to following approach to parse the json</p> <pre><code>public class Response&lt;T&gt; { public Date serverTime; public ResponseData&lt;T&gt;[] data; } public class ResponseDataBase { public int key1; } public class ResponseData&lt;T&gt; : ResponseDataBase { public T result; } </code></pre> <p>Here can <strong>T</strong> be following two classes </p> <pre><code>Class Result1 { public List&lt;string&gt; sample1 { get; set; } public string sample2 { get; set; } } Class Result2 { public List&lt;string&gt; sample3 { get; set; } public string sample4 { get; set; } } </code></pre> <p>I have these class declaration as reference, the class definition can be totally different.</p> <p>** How can I parse this json by specifying Result type.** I am using JSONFx.net for deserializing back to objects.</p> <p>Thanks</p>
    singulars
    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.
 

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