2016-11-14 2 views
0

У меня возникли проблемы, возвратив строку JSON обратно к выходу после того, как у меня есть De-Serialized.Возврат JSON к OutputBuffer

У меня есть следующие три класса, объявленные я генерировал из 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; } 

    } 

My JSON Response выглядит следующим образом.

{ 
     "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 
     } 
} 

Я могу выводить «успех» BOOL из ответа, но я не могу получить обратно что-нибудь еще из ответа, как я получаю ссылки «объект не указывает на экземпляр объекта. " Ошибка при попытке сделать следующее.

foreach (Application app in outPutResponse.jsonResponse.Applications) 
     { 
      ApplicationBuffer.AddRow(); 
      ApplicationBuffer.AppID = app.App_ID; 
      ApplicationBuffer.AppRef = app.App_Ref; 
      ApplicationBuffer.Status = app.Status; 

     } 

Я также не могу вернуть ответ «jsonResponse» к OUTPUTBUFFER с «не может неявно преобразовать jsonResponse в BlobColumn»

Я также не может вернуть значение отклика от outPutResponse.jsonResponse со следующими ошибками.

RawBuffer.AddRow(); 
    RawBuffer.ResponseSuccess = outPutResponse.Success; 
    RawBuffer.Response.AddBlobData(Encoding.ASCII.GetBytes(outPutResponse.jsonResponse)); 

Лучший перегружен матч метод 'System.Text.Encoding.GetBytes (символ [])' имеет некоторые недопустимые аргументы Аргумент 1: не может конвертировать из 'Script.Response' до 'гольца []

Это мой последний камень преткновения и не может показаться правильным. Может ли кто-нибудь помочь? Заранее спасибо.

ответ

2

Предполагая, что вы используете 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 вместо ofc:

public Response Response { get; set; } 
+0

Вы не представляете, насколько я ценю это прямо сейчас –

+0

@ LucasПеред приветствовать вас – Jim