2016-11-14 9 views
0

デシリアライズした後、JSON文字列を出力に戻す際に問題が発生しています。JSONをOutputBufferに戻す

私はjson2csharpから生成した以下の3つのクラスを宣言しています。

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

私はレスポンスから「成功」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」を返すカント

「暗黙的BlobColumnにjsonResponseを変換することはできません」私はまた、次のエラーでoutPutResponse.jsonResponseからの応答値を返すことはできません。 '[]チャー' に 'Script.Response' へ変換することができない。

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

ための最良のオーバーロードされたメソッドが一致 'System.Text.Encoding.GetBytes(charは[])' 引数1は、いくつかの無効な引数を有する

これは私の最終的な障害であり、この権利を得ることはできないようです。誰も助けることができますか?前もって感謝します。

答えて

2

あなたはNewtonsoft JSON.Netを使用していると仮定すると、それは賢明な考えです。

実際のプロパティ名がResponseの場合、プロパティ名をjsonResponseに変更しました。

あなたがしたい場合は、あなたがそうのよう

[JsonProperty("myproperty_name")] 

とプロパティを飾るために持って好きなように名前を変更します。私は上記の例をお勧めしますが、あなたが代わりResponseを使用することができ

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; } 
} 

ofc:

public Response Response { get; set; } 
+0

あなたはこれを今までにどれだけ高く評価しているのか分かりません。 –

+0

@LucasPerrettようこそ – Jim

関連する問題