【问题标题】:How do i save json Object to Assets folder using LocalStorage如何使用 LocalStorage 将 json 对象保存到 Assets 文件夹
【发布时间】:2023-03-06 17:49:01
【问题描述】:

我将网络中的数据序列化为 Json,我想将其保存到应用程序文件夹“Assets”中的路径中,如何使用本地存储?还是IsolatedStorage 是正确的选择?

string js = JsonConvert.SerializeObject(up, Formatting.Indented);
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
StorageFile textFile = await localFolder.CreateFileAsync("upcoming.Json", CreationCollisionOption.ReplaceExisting);
using (IRandomAccessStream textStream = await textFile.OpenAsync(FileAccessMode.ReadWrite))
{
    using (DataWriter textWriter = new DataWriter(textStream))
    {
        textWriter.WriteString(js);
        await textWriter.StoreAsync();
    }
}

【问题讨论】:

    标签: c# windows win-universal-app


    【解决方案1】:

    无法写入资产文件夹,但您可以写入 LocalStorage、RoamingStorage(跨设备同步)或 TemporaryStorage。这些存储只能供您的应用访问。

    以下是指南的链接,其中包含示例,可帮助您顺利上路。 http://jamescroft.co.uk/blog/uwp/how-to-implement-local-storage-in-universal-windows-apps/

    【讨论】:

    • 所以即使使用独立存储,我也无法写入资产?
    • 资产文件夹位于沙盒环境中,您只有读取权限。
    • 我只需要知道文件名就可以使用它......我猜这部分是固定的
    猜你喜欢
    • 2020-11-19
    • 2018-05-30
    • 2016-08-15
    • 2017-11-16
    • 1970-01-01
    • 2018-01-30
    • 2021-06-13
    • 2015-09-05
    • 2013-11-22
    相关资源
    最近更新 更多