c# - Autofill with REST API in windows 8.1 phone app -
i implementing city search want autofill functionality when select city want id sent api. populate other fields.
private async void autosuggestbox_textchanged(autosuggestbox sender, autosuggestboxtextchangedeventargs args) { if (args.reason == autosuggestionboxtextchangereason.userinput) { string text = sender.text; if (text.length >= 3) { getcities(text); sender.itemssource = await task<string[]>.run(() => { return this.getsuggestions(text); }); } else { sender.itemssource = new string[] { "no suggestions..." }; } } }
my response class
private async void getcities(string city) { try { string baseaddress = url.url + "searchcities?q="+city+"&access_token=" + tcm; httpclient httpclient = new httpclient(); string co = ""; var content = await httpclient.getasync(new uri(baseaddress)); if (!content.issuccessstatuscode) { tokengenerator tc = new tokengenerator(); tc.gettoken(); tcm = tokenmanager.accesst.access_tocken; httpclient client = new httpclient(); content = await client.getasync(new uri(baseaddress)); } co = await content.content.readasstringasync(); autofillhelper result = jsonconvert.deserializeobject<autofillhelper>(co); foreach (var item in result.data) { suggestions = new string [] {item.city} ; } } catch (exception ex) { dispatchertimer.stop(); throw new exception(ex.tostring()); } } private string[] getsuggestions(string text) { string[] result = null; result = suggestions.where(x => x.startswith(text)).toarray(); return result; }
my set
class autofill { public string city_id { get; set; } public string city { get; set; } } class autofillhelper { public list<autofill> data { get; set; } }
i want display response api person select it. run time error thrown. can please guide me has gone wrong.
any kind of appreciated...
Comments
Post a Comment