json.net - How to update JSON data object in the isolated storage of my Windows Phone 8 application -
i have listpicker item contain list of expense.
on clicking it, new xaml page opened , details of expense obtained.
there option edit , save.
so how should update particular json data object stored in isolated storage when user clicks update button.
my code here:
https://onedrive.live.com/redir?resid=83f2a501543779d4%211229
thank you
here code in updatexpenses.xaml.cs. please let me know going wrong.
after navigation page
protected override void onnavigatedto(system.windows.navigation.navigationeventargs e){
base.onnavigatedto(e); string datafromappsettings; expencesgroup data; navigationcontext.querystring.trygetvalue("selectedexpenceobject", out selectedindex); navigationcontext.querystring.trygetvalue("typeoftransaction", out transactiontype); if (transactiontype == expencesmodel.expencesgivenkey) { if (isolatedstoragesettings.applicationsettings.trygetvalue(expencesmodel.expencesgivenkey, out datafromappsettings)) { data = jsonconvert.deserializeobject<expencesgroup>(datafromappsettings); if (data != null) { thisexpence = data.expences[convert.toint32(selectedindex)]; this.datacontext = thisexpence; switchbetweenlistitems(thisexpence.typeoftransaction); switchbetweenlistitems(thisexpence.paidthrough); } } } else { if (isolatedstoragesettings.applicationsettings.trygetvalue(expencesmodel.expencestakenkey, out datafromappsettings)) { data = jsonconvert.deserializeobject<expencesgroup>(datafromappsettings); if (data != null) { thisexpence = data.expences[convert.toint32(selectedindex)]; this.datacontext = thisexpence; switchbetweenlistitems(thisexpence.typeoftransaction); switchbetweenlistitems(thisexpence.paidthrough); } } }
after clicking update button
private void update_expense(object sender, system.windows.input.gestureeventargs e) { thisexpence.amount = amount.text; messagebox.show(thisexpence.amount.tostring()); thisexpence.expensetitle = expensename.text; listpickeritem paidthroughlistpicker = (listpickeritem)paidthrough.selecteditem; thisexpence.paidthrough = (string)paidthroughlistpicker.content; thisexpence.expencestatus = (bool)paymentstatus.ischecked; listpickeritem listpickeritem = (listpickeritem)typeoftransaction.selecteditem; thisexpence.typeoftransaction = (string)listpickeritem.content; if (thisexpence.typeoftransaction == expencesmodel.expencesgivenkey) { var data = jsonconvert.serializeobject(app.viewmodel.given); isolatedstoragesettings.applicationsettings[expencesmodel.expencesgivenkey] = data; } else { var data = jsonconvert.serializeobject(app.viewmodel.taken); isolatedstoragesettings.applicationsettings[expencesmodel.expencestakenkey]. = data; } isolatedstoragesettings.applicationsettings.save(); navigationservice.navigate(new uri("/expencespage.xaml", urikind.relativeorabsolute)); }
step 1: can read json
data object isolatedstorage
, convert datacontract
using datacontractjsonserializer
. can update particular value on button click.
step 2: convert datacontract stream or json data object , store isolatedstorage.
you can refer this link step 1. refer how to: serialize , deserialize json data also
Comments
Post a Comment