c# - Xamarin Android deserialize local json file -
i got working json deserializer that's json file url. how can recreate , make work local json file? file in root of application, next mainactivity.
this working code 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 question: " + question.id + "."; edittext.layoutparameters = new viewgroup.layoutparams(viewgroup.layoutparams.matchparent,viewgroup.layoutparams.wrapcontent); layout.addview (edittext); } }
i got working.. had put .json file in assets folder, set build action androidasset , use next code:
string response; streamreader strm = new streamreader (assets.open ("form.json")); response = strm.readtoend (); list<vraag> vragen = jsonconvert.deserializeobject<list<vraag>>(response); foreach(vraag vraag in vragen) { if (vraag.type == "textfield") { var edittext = new edittext (this); edittext.text = "dit vraag: " + vraag.id + "."; edittext.layoutparameters = new viewgroup.layoutparams(viewgroup.layoutparams.matchparent,viewgroup.layoutparams.wrapcontent); layout.addview (edittext); } }
Comments
Post a Comment