[Unity][C#]合并两个有序数组为一个有序数组

...using System.Collections;using System.Collections.Generic;using UnityEngine;... private List<int> list_A = new List<int>() { 1,3,5,7,9 }; private List<int> list_B = new List<int>() { 2,4,6...
摘要由CSDN通过智能技术生成

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;

public class TestTwoArrays : MonoBehaviour
{
    private List<int> list_A = new List<int>()
    {
        1,3,5,7,9
    };
    private List<int> list_B = new List<int>()
    {
        2,4,6,8
    };

    private List<string> listStr_A = new List<string>()
    {
        "asdgfads345","cdfgb","edfghfdh12","gyukytuj"
    };

    private List<string> listStr_B = new List<string>()
    {
        "bytukjyu123","dtgyukjyu","freagdf","htyuk234"
    };

    private List<string> listStrCN_A = new List<string>()
    {
        "一是大法官cvb","三益田假日","五分工表sdfg","七大师傅"
    };
    private List<string> listStrCN_B = new List<string>()
    {
        "二345 大师傅","四sdrg342
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Unity 中使用 LitJson 添加一个数组,你可以按照以下骤进行操作: 1. 首先,确保你已经将 LitJson 添加到 Unity 项目中。你可以从 LitJson 的 GitHub 页面(https://github.com/LitJSON/litjson)下载最新版本的 LitJson,并将其导入到 Unity 项目中。 2. 在你的代码中,首先导入 LitJson 库: ```csharp using LitJson; ``` 3. 创建一个包含要添加到数组中的数据的 List 或 Array 对象。假设你想要添加一组整数到数组中: ```csharp List<int> numberList = new List<int>(); numberList.Add(1); numberList.Add(2); numberList.Add(3); ``` 4. 使用 LitJson 的 JsonMapper.ToJson 方法将 List 或 Array 对象转换为 JSON 字符串: ```csharp string json = JsonMapper.ToJson(numberList); ``` 5. 现在,你可以将生成的 JSON 字符串添加到你的其他 JSON 对象中。例如,如果你有一个包含其他属性的 JSON 对象,你可以使用 LitJson 创建一个包含数组的 JSON 对象: ```csharp JsonData jsonObject = new JsonData(); jsonObject["property1"] = "value1"; jsonObject["property2"] = "value2"; jsonObject["array"] = JsonMapper.ToObject(json); ``` 6. 最后,如果你想将 JSON 对象转换回原始数据类型,你可以使用 LitJson 的 JsonMapper.ToObject 方法: ```csharp List<int> deserializedList = JsonMapper.ToObject<List<int>>(json); ``` 这样,你就可以在 Unity 中使用 LitJson 添加一个数组了。记得根据你的需求进行适当的类型转换。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值