title: A better way to deserialize JSON?
body: <p>I am posting to an API that may return either 1 of the following 2 formats of JSON strings:</p>
  
  <pre><code>{
  "MessageType": 6,
  "Message": "Unable to SAVE new record. Invalid posted data."
  }
  </code></pre>
  
  <p>or </p>
  
  <pre><code>{
  "Model": {
      "Id": "1-6Q0RZ9",
      ...
  
           },   
  "ResponseResult": {
      "MessageType": 10,
      "Message": "Successfully saved, Record Id = 1-6Q0RZ9"
                    }
  }
  </code></pre>
  
  <p>I need to retrieve the results from MessageType and have tried every if condition I can think of to read the results, because the syntax or retrieving the key:value is different for each JSON string, and there are no other flags to trigger one or the other. So the code I used is:</p>
  
  <pre><code>string result = eml.PostData("API/Save", dataJSON.ToString());
  var returnresult = new JavaScriptSerializer().Deserialize&lt;dynamic&gt;(result);
  try {
    var responseresults = returnresult["ResponseResult"];
    rr = responseresults["MessageType"];
    rrtxt = responseresults["Message"];
  } catch (Exception ex) {
    rr = returnresult["MessageType"];
    rrtxt = returnresult["Message"];
  }
  </code></pre>
  
  <p>Which works great. If there is a valid Db post it returns the second JSON which is parsed correctly by the TRY statement, if not it throws a "key not found" error and parses the returned string in the CATCH statement (the first JSON example). Obviously this is horrible code but I cannot think of another way to do this, and I was wondering if anyone had suggestions? (please?)</p>
  
  <p>Thanx in advance.</p>