【发布时间】:2026-02-09 02:25:01
【问题描述】:
我有一个可用的 JSON 反序列化器,但它是来自 URL 的 JSON 文件。如何重新创建它并使其与本地 JSON 文件一起使用?该文件位于我的应用程序的根目录中,在我的 MainActivity 旁边。
这是来自 URL 的工作代码:
var client = new WebClient();
var response = client.DownloadString(new Uri("http://www.mywebsite.nl/form.json"));
List<Question> questions = JsonConvert.DeserializeObject<List<Question>>(response);
foreach(Question question in questions)
{
if (question.type == "textField") {
var editText = new EditText (this);
editText.Text = "This is question: " + question.id + ".";
editText.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent,ViewGroup.LayoutParams.WrapContent);
layout.AddView (editText);
}
}
【问题讨论】:
标签: c# android json xamarin.android xamarin