我使用RestSharp检索json字符串并将其显示在列表视图中。我希望,一旦单击列表项,便能够使用文本框/ edittext中的值更新json字符串中的元素。
这个想法是将数据发送到新活动,将其用作应更新内容的职位。 edittext / textbox插入一个值以根据位置更新json字符串中的旧值。
受保护的覆盖无效OnCreate(捆绑的saveInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Update);
text = Intent.GetStringExtra("MyData") ?? string.Empty;
lbl = FindViewById<TextView>(Resource.Id.label);
if (!string.IsNullOrEmpty(text))
{
lbl.Text = text;
}
btn.Click += btn_click;
}
private void btn_click(对象发送者,EventArgs e)
{
modifyJson();
}
公共异步无效ModifyJson()
{
IRestClient client = new RestClient("http://10.0.86.171:8810");
IRestRequest cpf = new RestRequest("/TestRest/rest/TestRestService/UserBE", Method.PUT);
cpf.RequestFormat = DataFormat.Json;
cpf.RootElement = "ttSmartUser";
IRestResponse response = client.Execute<TtSmartUser>(cpf);
var cont = response.Content;
int frontbrac = cont.IndexOf("[");
string rem = cont.Remove(0, frontbrac);
int backbrac = rem.IndexOf("]");
int strLengt = rem.Length;
int count = strLengt - backbrac - 1;
rem = rem.Remove(backbrac + 1, count);
var parse2 = JsonConvert.DeserializeObject<List<TtSmartUser>>(rem);
try
{
await Task.Run(() =>
{
foreach (var test in parse2)
{
sc.Post(new SendOrPostCallback(o =>
{
adapter.GetPosition(text);
adapter.Add(modif.Text);
adapter.NotifyDataSetChanged();
}), text);
}
});
}
catch (Exception e)
{
Toast.MakeText(this, "" + e.Message, ToastLength.Long).Show();
}
}
公共类TtSmartUser
{
public string UserGuid { get; set; }
public string UserName { get; set; }
public string LanguageGuid { get; set; }
public string UserFullName { get; set; }
public string UserEmail { get; set; }
public string UserPassword { get; set; }
public string UserPasswordChangedDate { get; set; }
public DateTime? UserLastLogin { get; set; }
public string LoginCompanyGuid { get; set; }
public string ManagerUserGuid { get; set; }
public object UserSecurityId { get; set; }
}
公共类RootObject {
public List<TtSmartUser> ttSmartUser { get; set; }
}