Konwertuj obiekt na łańcuch JSON w C # [duplikat]
Możliwy duplikat:
Przekształć obiekt C # w łańcuch JSON w .NET 4
W Javie mam kod do konwersji obiektu java na łańcuch JSON. Jak zrobić podobny w C #? jakiej biblioteki JSON powinienem użyć?
Dzięki.
Kod JAVA
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
public class ReturnData {
int total;
List<ExceptionReport> 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();
}
...
}