title: Convert object to JSON string in C#
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/6201529/turn-c-sharp-object-into-a-json-string-in-net-4">Turn C# object into a JSON string in .NET 4</a>  </p>
  </blockquote>
  
  
  
  <p>In the Java, I have a code to convert java object to JSON string. How to do the similar in the C# ? which JSON library I should use ?</p>
  
  <p>Thanks.</p>
  
  <p>JAVA code</p>
  
  <pre><code>import net.sf.json.JSONArray;
  import net.sf.json.JSONObject;
  
  public class ReturnData {
      int total;
  
      List&lt;ExceptionReport&gt; exceptionReportList;  
  
      public String getJSon(){
          JSONObject json = new JSONObject(); 
  
          json.put("totalCount", total);
  
          JSONArray jsonArray = new JSONArray();
          for(ExceptionReport report : exceptionReportList){
              JSONObject jsonTmp = new JSONObject();
              jsonTmp.put("reportId", report.getReportId());      
              jsonTmp.put("message", report.getMessage());            
              jsonArray.add(jsonTmp);         
          }
  
          json.put("reports", jsonArray);
          return json.toString();
      }
      ...
  }
  </code></pre>