我正在关注这个问题ListView Get Multiple Entry Values to validate and send我现在需要序列化数据以将其发送到服务器,我已经做到了这一点:
public class SurveyList
{
public List<QuestionList> Questions { get; set; }
}
public class QuestionList
{
public string QuestionLabel { get; set; }
public string QuestionCode { get; set; }
}
public partial class SurveyPage : ContentPage
{
private List<QuestionList> survey;
public SurveyPage()
{
InitializeComponent();
survey = new List<QuestionList>
{
new QuestionList { QuestionLabel = "Question 1?", QuestionCode = "01" },
new QuestionList { QuestionLabel = "Question 2?", QuestionCode = "02" }
};
surveyList.ItemsSource = survey;
}
void Button_Clicked(object sender, System.EventArgs e)
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://myip");
foreach (var getValues in survey)
{
Dictionary<string, string> listViewData = new Dictionary<string, string>()
{
{ "Question", getValues.QuestionLabel },
{ "Answer", getValues.QuestionCode }
};
var listViewDataContent = new FormUrlEncodedContent(listViewData);
var response = client.PostAsync("/api/GetData", listViewDataContent);
}
}
}
请帮助我正确获取所有数据以通过 POST 发送。不知道如何收集所有数据,因为我得到的数据是动态的。
注意:那里显示的数据是静态的,但应该是从同一个 API 获取数据
侃侃无极
浮云间
相关分类