返回 JSON 到 OutputBuffer
Returning JSON to OutputBuffer
我在反序列化 return 将 JSON 字符串返回到输出时遇到问题。
我声明了以下三个 类 是我从 json2csharp 生成的:
public class Application
{
public int App_ID { get; set; }
public string App_Ref { get; set; }
public string Status { get; set; }
public string Error_Code { get; set; }
public string Error_Message { get; set; }
public string Create_Dt { get; set; }
public string Modify_Dt { get; set; }
public string Client_Name { get; set; }
public string Client_Code { get; set; }
public string Centrelink_Status { get; set; }
}
public class Response
{
public List<Application> Applications { get; set; }
public string Current_Dt { get; set; }
public string Last_App_Dt { get; set; }
public int Count { get; set; }
public int Total { get; set; }
}
public class RootObject
{
public bool Success { get; set; }
public Response jsonResponse { get; set; }
}
我的 JSON 回复如下:
{
"Success": true,
"Response": {
"Applications": [
{
"App_ID": 2877582,
"App_Ref": "Odonnell",
"Status": "Complete",
"Error_Code": 0,
"Error_Message": "",
"Create_Dt": "2016-10-09 19:28:18.867 +00:00",
"Modify_Dt": "2016-10-09 19:33:10.810 +00:00",
"Client_Name": "Aussie Bike Auto & Boat Loans South",
"Client_Code": "GGT31",
"Centrelink_Status": "Receiving_Logons"
},
{
"App_ID": 2878070,
"App_Ref": "alliso",
"Status": "Quicklink",
"Error_Code": null,
"Error_Message": null,
"Create_Dt": "2016-10-09 21:55:49.220 +00:00",
"Modify_Dt": "2016-10-09 21:55:49.220 +00:00",
"Client_Name": "KChristoforidis",
"Client_Code": "GGT05",
"Centrelink_Status": "Receiving_Logons"
}...
],
"Current_Dt": "2016-11-13 22:52:41.581 +00:00",
"Last_App_Dt": "2016-10-11 01:42:25.470 +00:00",
"Count": 65,
"Total": 65
}
}
我能够从响应中输出 "Success" 布尔值,但是我无法从响应中取回任何其他内容,因为我得到的是 "Object reference not set to an instance of an object." 当我尝试执行以下操作时出错:
foreach (Application app in outPutResponse.jsonResponse.Applications)
{
ApplicationBuffer.AddRow();
ApplicationBuffer.AppID = app.App_ID;
ApplicationBuffer.AppRef = app.App_Ref;
ApplicationBuffer.Status = app.Status;
}
我也无法 return 对 outputBuffer 的响应 "jsonResponse" 出现错误 "can not implicitly convert jsonResponse to BlobColumn"
我也无法 return 来自 outPutResponse.jsonResponse 的响应值,并出现以下错误:
RawBuffer.AddRow();
RawBuffer.ResponseSuccess = outPutResponse.Success;
RawBuffer.Response.AddBlobData(Encoding.ASCII.GetBytes(outPutResponse.jsonResponse));
'System.Text.Encoding.GetBytes(char[])' 的最佳重载方法匹配有一些无效参数
参数 1:无法从 'Script.Response' 转换为 'char[]'
这是我最后的绊脚石,我似乎无法做到这一点。
假设您正在使用 Newtonsoft JSON.Net,因为这是一个聪明的主意。
您已将 属性 名称更改为 jsonResponse
,而实际 属性 名称为 Response
。
如果您想更改名称,您必须使用
修饰属性
[JsonProperty("myproperty_name")]
像这样:
public class Application
{
[JsonProperty("App_ID")]
public int App_ID { get; set; }
[JsonProperty("App_Ref")]
public string App_Ref { get; set; }
[JsonProperty("Status")]
public string Status { get; set; }
[JsonProperty("Error_Code")]
public int? Error_Code { get; set; }
[JsonProperty("Error_Message")]
public string Error_Message { get; set; }
[JsonProperty("Create_Dt")]
public string Create_Dt { get; set; }
[JsonProperty("Modify_Dt")]
public string Modify_Dt { get; set; }
[JsonProperty("Client_Name")]
public string Client_Name { get; set; }
[JsonProperty("Client_Code")]
public string Client_Code { get; set; }
[JsonProperty("Centrelink_Status")]
public string Centrelink_Status { get; set; }
}
public class Response
{
[JsonProperty("Applications")]
public IList<Application> Applications { get; set; }
[JsonProperty("Current_Dt")]
public string Current_Dt { get; set; }
[JsonProperty("Last_App_Dt")]
public string Last_App_Dt { get; set; }
[JsonProperty("Count")]
public int Count { get; set; }
[JsonProperty("Total")]
public int Total { get; set; }
}
public class RootObject
{
[JsonProperty("Success")]
public bool Success { get; set; }
[JsonProperty("Response")]
public Response jsonResponse { get; set; }
}
虽然我推荐上面的示例,但您也可以使用 Response
而不是 c:
public Response Response { get; set; }
我在反序列化 return 将 JSON 字符串返回到输出时遇到问题。
我声明了以下三个 类 是我从 json2csharp 生成的:
public class Application
{
public int App_ID { get; set; }
public string App_Ref { get; set; }
public string Status { get; set; }
public string Error_Code { get; set; }
public string Error_Message { get; set; }
public string Create_Dt { get; set; }
public string Modify_Dt { get; set; }
public string Client_Name { get; set; }
public string Client_Code { get; set; }
public string Centrelink_Status { get; set; }
}
public class Response
{
public List<Application> Applications { get; set; }
public string Current_Dt { get; set; }
public string Last_App_Dt { get; set; }
public int Count { get; set; }
public int Total { get; set; }
}
public class RootObject
{
public bool Success { get; set; }
public Response jsonResponse { get; set; }
}
我的 JSON 回复如下:
{
"Success": true,
"Response": {
"Applications": [
{
"App_ID": 2877582,
"App_Ref": "Odonnell",
"Status": "Complete",
"Error_Code": 0,
"Error_Message": "",
"Create_Dt": "2016-10-09 19:28:18.867 +00:00",
"Modify_Dt": "2016-10-09 19:33:10.810 +00:00",
"Client_Name": "Aussie Bike Auto & Boat Loans South",
"Client_Code": "GGT31",
"Centrelink_Status": "Receiving_Logons"
},
{
"App_ID": 2878070,
"App_Ref": "alliso",
"Status": "Quicklink",
"Error_Code": null,
"Error_Message": null,
"Create_Dt": "2016-10-09 21:55:49.220 +00:00",
"Modify_Dt": "2016-10-09 21:55:49.220 +00:00",
"Client_Name": "KChristoforidis",
"Client_Code": "GGT05",
"Centrelink_Status": "Receiving_Logons"
}...
],
"Current_Dt": "2016-11-13 22:52:41.581 +00:00",
"Last_App_Dt": "2016-10-11 01:42:25.470 +00:00",
"Count": 65,
"Total": 65
}
}
我能够从响应中输出 "Success" 布尔值,但是我无法从响应中取回任何其他内容,因为我得到的是 "Object reference not set to an instance of an object." 当我尝试执行以下操作时出错:
foreach (Application app in outPutResponse.jsonResponse.Applications)
{
ApplicationBuffer.AddRow();
ApplicationBuffer.AppID = app.App_ID;
ApplicationBuffer.AppRef = app.App_Ref;
ApplicationBuffer.Status = app.Status;
}
我也无法 return 对 outputBuffer 的响应 "jsonResponse" 出现错误 "can not implicitly convert jsonResponse to BlobColumn"
我也无法 return 来自 outPutResponse.jsonResponse 的响应值,并出现以下错误:
RawBuffer.AddRow();
RawBuffer.ResponseSuccess = outPutResponse.Success;
RawBuffer.Response.AddBlobData(Encoding.ASCII.GetBytes(outPutResponse.jsonResponse));
'System.Text.Encoding.GetBytes(char[])' 的最佳重载方法匹配有一些无效参数 参数 1:无法从 'Script.Response' 转换为 'char[]'
这是我最后的绊脚石,我似乎无法做到这一点。
假设您正在使用 Newtonsoft JSON.Net,因为这是一个聪明的主意。
您已将 属性 名称更改为 jsonResponse
,而实际 属性 名称为 Response
。
如果您想更改名称,您必须使用
修饰属性[JsonProperty("myproperty_name")]
像这样:
public class Application
{
[JsonProperty("App_ID")]
public int App_ID { get; set; }
[JsonProperty("App_Ref")]
public string App_Ref { get; set; }
[JsonProperty("Status")]
public string Status { get; set; }
[JsonProperty("Error_Code")]
public int? Error_Code { get; set; }
[JsonProperty("Error_Message")]
public string Error_Message { get; set; }
[JsonProperty("Create_Dt")]
public string Create_Dt { get; set; }
[JsonProperty("Modify_Dt")]
public string Modify_Dt { get; set; }
[JsonProperty("Client_Name")]
public string Client_Name { get; set; }
[JsonProperty("Client_Code")]
public string Client_Code { get; set; }
[JsonProperty("Centrelink_Status")]
public string Centrelink_Status { get; set; }
}
public class Response
{
[JsonProperty("Applications")]
public IList<Application> Applications { get; set; }
[JsonProperty("Current_Dt")]
public string Current_Dt { get; set; }
[JsonProperty("Last_App_Dt")]
public string Last_App_Dt { get; set; }
[JsonProperty("Count")]
public int Count { get; set; }
[JsonProperty("Total")]
public int Total { get; set; }
}
public class RootObject
{
[JsonProperty("Success")]
public bool Success { get; set; }
[JsonProperty("Response")]
public Response jsonResponse { get; set; }
}
虽然我推荐上面的示例,但您也可以使用 Response
而不是 c:
public Response Response { get; set; }