我正在尝试保存从Windows PhoneJSON
返回的对象。我从下面的代码开始,但我不完全确定如何将文件实际写入独立存储或将其保存为什么格式(XML、TXT 等)。Azure Mobile Services
isolated storage
string offlineData = Path.Combine("WPTracker", "Offline");
string offlineDataFile = Path.Combine(offlineData, "phones.xml");
var store = IsolatedStorageFile.GetUserStoreForApplication();
//Query
try
{
phoneList = await phoneTable
.Where(PhoneItem => PhoneItem.Publish == true)
.OrderBy(PhoneItem => PhoneItem.FullName)
.ToListAsync();
}
catch (MobileServiceInvalidOperationException f)
{
MessageBox.Show(f.Response.Content.ToString(),
string.Format("{0} (HTTP {1})",
f.Response.Content,
f.Response.StatusCode), MessageBoxButton.OK);
}
//Write
IsolatedStorageFileStream dataFile = null;
dataFile = store.OpenFile(offlineDataFile, FileMode.Create);
DataContractSerializer ser = new DataContractSerializer(typeof(IEnumerable<Phones>));
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
JsonWriter jWriter = new JsonTextWriter(sw);
ser.WriteObject(dataFile, phoneList);
dataFile.Close();
有什么建议么?:)
编辑
我决定使用 JSON 文件而不是 XML 将数据写入独立存储。这是因为我来自 Azure 移动服务的数据是以 JSON 格式发送的。无需将其转换为 XML。可以在下面找到一个链接!