我的JSON如下所示,我无法解析此问题。不确定如何从foreach中查看内容...
我的restSharp代码是
var client = new RestClient("https://survey.qualtrics.com//WRAPI/ControlPanel/api.php?API_SELECT=ControlPanel&Version=2.5&Request=getPanel&User=dgfdhfgh&Token=DfghgfhghjUNUGaefghjP&Format=JSON&LibraryID=UR_5cJwNFX8lwFXFwp&PanelID=ML_b8IoBrawfm3MCd7");
var request = new RestRequest(Method.GET);
client.AddHandler("application/json", new JsonDeserializer());
var result = client.Execute<List<RootObject>>(request);
if (result != null && (result.StatusCode == HttpStatusCode.OK) ) // It's probably not necessary to test both
{
foreach (var j in result.Content)
{
XXXXXXX;
}
和JSON如下
[
{"RecipientID":"MLRP_1BNnjFoPFgeajfT","FirstName":"Darfghryl","LastName":"Wright","Email":"heoaxcvdcbk7@gmail.com","ExternalDataReference":null,"Unsubscribed":"0","EmbeddedData":{"Participant ID":"16941","DateTaken":"20160710","TriggerResponseID":"R_VKe0amWmZIXcuZ3","TriggerSurveyID":"SV_eA35TXE0iRlexBX","AllEmailsSchduledForSurvey2":"yes"}},
{"RecipientID":"MLRP_cCjJTFP6MxpZFhH","FirstName":"fghfgh","LastName":"Henzell","Email":"fghfgh@gmail.com","ExternalDataReference":null,"Unsubscribed":"0","EmbeddedData":{"Participant ID":"29377","DateTaken":"20160711","TriggerResponseID":"R_z14mwG7l7DBCYg1","TriggerSurveyID":"SV_eA35TXE0iRlexBX","AllEmailsSchduledForSurvey2":"yes"}}]
我的课程如下,请帮助
public class EmbeddedData
{
public string Participant_ID { get; set; }
public string DateTaken { get; set; }
public string TriggerResponseID { get; set; }
public string TriggerSurveyID { get; set; }
public string AllEmailsSchduledForSurvey2 { get; set; }
public string AllEmailsSchduledForSurvey3 { get; set; }
}
public class RootObject
{
public string RecipientID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public object ExternalDataReference { get; set; }
public string Unsubscribed { get; set; }
public List<EmbeddedData> EmbeddedData { get; set; }
}
答案 0 :(得分:0)
请尝试
if (result != null && (result.StatusCode == HttpStatusCode.OK) )
{
// here I made changes
RestSharp.Deserializers.JsonDeserializer deserial = new JsonDeserializer();
List<RootObject> content = deserial.Deserialize<List<RootObject>>(result);
foreach (var cont in content)
{
// Do your Stuff
}
}