【发布时间】:2016-09-04 14:22:50
【问题描述】:
逻辑是在按钮单击事件中编写的,该事件获取对象数组。在 ForEach 循环中,我将每个对象转换为 JSON,但我无法将其合并为最终的 json 对象。我收到错误,因为无法通过实例引用访问 'string.Concat(params string[])';改为使用类型名称对其进行限定。
protected void Button2_Click(object sender, EventArgs e)
{
String json = "";
String jsonoutput = "";
foreach (SAFWebReference.Usagr value in response.PRoles)
{
json = new JavaScriptSerializer().Serialize(value);
jsonoutput = jsonoutput.Concat(json);
}
}
【问题讨论】:
-
你不能连接 json 字符串来形成一个有效的 json...序列化 response.PRoles ....
{a:1}是一个有效的 json 但{a:1}{a:2}不是。 .. -
使用 jsonoutput = jsonoutput + json;如果它只是纯粹用于合并而不是最后的有效 json
-
...而
Concat是static方法,因此您不能像在实例上那样使用它。 -
为什么你的respnse.PRoles不能直接序列化?
-
似乎你想要
jsonoutput = string.Concat(jsonoutput, json);,但我认为你走的不是正确的道路......