【发布时间】:2012-07-05 22:04:16
【问题描述】:
在 Java 中,我有一个将 java 对象转换为 JSON 字符串的代码。如何在 C# 中做类似的事情?我应该使用哪个 JSON 库?
谢谢。
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();
}
...
}
【问题讨论】:
-
您应该在 C# 中尝试一下,并向我们展示您正在尝试的代码。正如所写,这个问题只不过是一个远离答案的谷歌搜索,并没有增加价值。请编辑您的问题以包含您在 C# 中尝试过的内容以及无效的内容。
-
@George Stocker 他在询问有关序列化的问题,而您正在显示反序列化的副本,为什么?
-
@GovindKamalaPrakashMalviya 在无数重复中,我误读并选择了错误的那个。感谢您了解这一点。