私は、シリアル化されたJSONレスポンスの値を別の出力に戻そうとしていますが、出力するときはRootObjectの属性のみが表示されます。 Json Stringを複数の出力に変換する
は、SSISスクリプトコンポーネントでは、私は、次の出力Iは、以下のクラスを宣言したを作成しました。
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 Response { get; set; }
}
生のJsonレスポンスはこのように見えます。
{
"Success": true,
"Response": {
"Applications": [
{
"App_ID": 1638486,
"App_Ref": "Test Example",
"Status": "Complete",
"Error_Code": null,
"Error_Message": null,
"Create_Dt": "2014-05-14 03:09:01.030 +00:00",
"Modify_Dt": "2014-05-14 03:10:59.757 +00:00",
"Client_Name": "Silver Chef",
"Client_Code": "SLVC01",
"Centrelink_Status": "Receiving_Logons"
},
{
"App_ID": 1637906,
"App_Ref": "SME Demo",
"Status": "Complete",
"Error_Code": null,
"Error_Message": null,
"Create_Dt": "2015-10-08 03:07:26.793 +00:00",
"Modify_Dt": "2015-10-08 03:23:32.833 +00:00",
"Client_Name": "Silver Chef",
"Client_Code": "SLVC01",
"Centrelink_Status": "Receiving_Logons"
},
{
"App_ID": 1585286,
"App_Ref": "Test",
"Status": "Receiving_Logons",
"Error_Code": null,
"Error_Message": null,
"Create_Dt": "2015-12-04 03:12:49.617 +00:00",
"Modify_Dt": "2015-12-04 03:12:49.617 +00:00",
"Client_Name": "Silver Chef",
"Client_Code": "SLVC01",
"Centrelink_Status": "Receiving_Logons"
},
{
"App_ID": 1585398,
"App_Ref": "Test",
"Status": "Receiving_Logons",
"Error_Code": null,
"Error_Message": null,
"Create_Dt": "2015-12-04 03:27:59.023 +00:00",
"Modify_Dt": "2015-12-04 03:27:59.023 +00:00",
"Client_Name": "Silver Chef",
"Client_Code": "SLVC01",
"Centrelink_Status": "Receiving_Logons"
},
{
"App_ID": 1585400,
"App_Ref": "Test",
"Status": "Receiving_Logons",
"Error_Code": null,
"Error_Message": null,
"Create_Dt": "2015-12-04 03:28:22.903 +00:00",
"Modify_Dt": "2015-12-04 03:28:22.903 +00:00",
"Client_Name": "Silver Chef",
"Client_Code": "SLVC01",
"Centrelink_Status": "Receiving_Logons"
}
],
"Current_Dt": "2016-11-11 01:01:01.743 +00:00",
"Last_App_Dt": "2016-10-03 22:48:56.397 +00:00",
"Count": 500,
"Total": 1870
}
}
このメソッドは、これを送信して受信するために使用されています。これはエラーなしでデシリアライズされているようです。私は "成功"属性を出力することができます。
private RootObject GetWebServiceResult(string vAPIUrl)
{
string vAPIToken = Variables.APIToken;
//Create Web Request
HttpWebRequest apireq = (HttpWebRequest)WebRequest.Create(vAPIUrl);
apireq.ContentType = "application/json";
apireq.Method = "POST";
string jsonPostStr = "{\"Settings\": {\"API_Token\": \"" + vAPIToken + "\"}, \"Payload\": {}}";
byte[] postString = Encoding.UTF8.GetBytes(jsonPostStr);
apireq.ContentLength = postString.Length;
Stream jsonStream = apireq.GetRequestStream();
jsonStream.Write(postString, 0, postString.Length);
jsonStream.Close();
// Get Web Response
HttpWebResponse apirsp = (HttpWebResponse)apireq.GetResponse();
RootObject jsonResponse = null;
Stream jsonRspStream = apirsp.GetResponseStream();
string apiResponseString = null;
using (StreamReader reader = new StreamReader(jsonRspStream))
{
apiResponseString = reader.ReadToEnd();
Console.WriteLine(apiResponseString);
reader.Close();
}
JavaScriptSerializer returnJson = new JavaScriptSerializer();
//var serialJsonStr = returnJson.Serialize(apiResponseString);
System.Windows.Forms.MessageBox.Show(apiResponseString);
jsonResponse = returnJson.Deserialize<RootObject>(apiResponseString);
return jsonResponse;
}
しかし、アプリケーション出力バッファに書き込んで返すと、成功と応答のみが表示されます。 (文字列への出力の応答もどちらも8000文字を超えていると思われますが)
私はこれを見て、各アプリケーションの値を設定しようとします。
私のforeach文に次のエラーが表示されます。
" 'ScriptMain.Responseは' 'GetEnumeratorメソッド' の 公開定義が含まれていないので、foreach文はタイプ の変数のScriptMain.Response"を操作することはできません" 助けてください!これが私を狂ってしまう!何が間違っているのですか?
あなたの 'Response'オブジェクトは列挙する' List'ではありません。 'Application'オブジェクトをループする場合は、' outPutResponse.Response.Applications'を実行する必要があります。そうでなければ、他のものはよさそうだ。 – Searching
コードの必要な/関連するセクションのみを追加してください。 – Rahul
Rahul、私は私が得たエラーに関連するものとして投稿したと思います。 –