数据持久化(保存Json文件)---Newtonsoft Json

这篇博客详细介绍了如何利用Newtonsoft Json库将数据持久化到Json文件中,为开发者提供了一种实用的数据存储解决方案。
摘要由CSDN通过智能技术生成

Newtonsoft Json 库

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.IO;
using System.Text;
using GFW;
using Newtonsoft.Json;

//public class UserConfigData
//{
//    public Dictionary<string, object> configDataDic = new Dictionary<string, object>();
//}
public class UserPersonData
{
    public string curUserID;
    public Dictionary<string, object> curUserDataDic = new Dictionary<string, object>();
}

public class GSetting {
    static string curUserID = "data";
    static string _saveDataPath = Application.dataPath + "/../WriteablePath/json/_current_userdata.json";
    // ----SetConfig
    public static void SetValue(string dataKey, object dataValue)
    {
        if (string.IsNullOrEmpty(dataKey))
        {
            Debug.Log(" is null !");
            return;
        }
        if (RefreshData(dataKey,dataValue))
        {
            return;
        }
        UserPersonData _newUserConfigData = new UserPersonData();
        _newUserConfigData.curUserDataDic[dataKey] = dataValue;

        string _saveData = JsonConvert.SerializeObject(_newUserConfigData);
        if (!string.IsNullOrEmpty(_saveData))
        {
            _saveData = _saveData + "\r\n";
     
使用C# Newtonsoft Json通过json数据,解码json生成用于保存数据json类,通过json生成类代码,支持子类 自动 如 [{"itemsize":437,"pageId":1,"erpNickShopObj":null,"itemjbxx":[{"num":94628,"numIid":40239293981,"outerId":"异常1元连接","picUrl":"http://img04.taobaocdn.com/bao/uploaded/i4/TB1rdpFGXXXXXc5XFXXXXXXXXXX_!!1-item_pic.gif","price":"1.00","title":"[Enni.kr]<恩妮韩品>补邮费/订单异常关闭专拍连接","volume":0},{"num":65592,"numIid":36048181106,"outerId":"爱茉莉沐浴露套装200ml*3","picUrl":"http://img03.taobaocdn.com/bao/uploaded/i3/516137599/TB21kzXXVXXXXcUXXXXXXXXXXXX_!!516137599.jpg","price":"52.00","title":"韩国进口爱茉莉happybath 沐浴露 柠檬 玫瑰 薰衣草 200ml*3套装","volume":0},{"num":59765,"numIid":38272119734,"outerId":"7难题牙膏 绿款","picUrl":"http://img01.taobaocdn.com/bao/uploaded/i1/516137599/TB2xDbXXVXXXXbbXXXXXXXXXXXX_!!516137599.jpg","price":"9.90","title":"韩国进口LG贝瑞奥/倍瑞奥7难题解决牙膏7功能合一强健120G绿色","volume":0},{"num":59764,"numIid":38288409657,"outerId":"黄金皂2件套礼盒","picUrl":"http://img04.taobaocdn.com/bao/uploaded/i4/516137599/TB2XBbXXVXXXXbKXXXXXXXXXXXX_!!516137599.jpg","price":"90.00","title":"包邮 韩国纯金皂 24K金美容皂 天然特效美容黄金皂 2件套装 礼盒","volume":0},{"num":59763,"numIid":38272395230,"outerId":"7难题牙膏 蓝款","picUrl":"http://img02.taobaocdn.com/bao/uploaded/i2/516137599/TB204vXXVXXXXa5XpXXXXXXXXXX_!!516137599.jpg","price":"9.90","title":"韩国LG 贝瑞奥/倍瑞奥7难题解决牙膏 7功能合一 原味 120G 蓝色","volume":0},{"num":59758,"numIid":38278150798,"outerId":"9928牙膏绿色款","picUrl":"http://img03.taobaocdn.com/bao/uploaded/i3/516137599/TB2KDDXXVXXXXaEXXXXXXXXXXXX_!!516137599.jpg","price":"9.90","title":"韩国 LG贝瑞奥/倍瑞奥9928牙膏 强齿美白牙膏 120G 绿色","volume":0},{"num":59751,"numIid":38288605749,"outerId":"9928牙膏蓝色款","picUrl":"http://img04.taobaocdn.com/bao/uploaded/i4/516137599/TB2n9HXXVXXXXbxXXXXXXXXXXXX_!!516137599.jpg","price":"9.90","title":"韩国 LG 倍瑞奥 9928 牙膏 抗菌 牙龈护理 防蛀牙固定牙齿 120g","volume":0},{"num":59741,"numIid":38301128090,"outerId":"9928牙膏红色款","picUrl":"http://img01.taobaocdn.com/bao/uploaded/i1/516137599/TB2PATXXVXXXXcHXXXXXXXXXXXX_!!516137599.jpg","price":"9.90","title":"韩国 LG贝瑞奥/倍瑞奥9928牙膏 消炎
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值