U3d-Json读取数组

2024-04-12 15:58
文章标签 读取 数组 json u3d

本文主要是介绍U3d-Json读取数组,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

U3d-Json读取数组


Json文件:

{"level1":["[1,1,1,1,1,1,1,1,1,1]","[1,1,1,1,1,1,0,4,1,1]","[1,1,1,1,1,1,0,0,1,1]","[1,1,1,1,1,1,3,0,1,1]","[1,1,1,1,1,1,0,0,1,1]","[1,1,1,1,1,1,0,0,1,1]","[1,1,1,1,1,1,0,0,1,1]","[1,1,1,1,1,1,1,1,1,1]"],"level2":["[1,1,1,1,1,1,1,1,1,1]","[1,1,1,3,0,1,2,1,1,1]","[1,1,1,0,0,1,0,1,1,1]","[1,1,1,0,0,0,0,0,4,1]","[1,1,1,0,0,0,0,0,0,1]","[1,1,1,1,0,1,0,0,1,1]","[1,1,1,1,0,1,0,0,1,1]","[1,1,1,1,1,1,1,1,1,1]"],"level3":["[1,1,1,1,1,1,1,1,1,1]","[1,1,1,0,0,0,0,1,1,1]","[1,1,0,0,0,0,0,0,0,1]","[1,1,0,1,1,1,0,0,0,1]","[1,0,0,0,1,1,0,0,0,1]","[1,4,0,0,0,1,2,0,3,1]","[1,1,0,0,0,1,0,0,0,1]","[1,1,1,1,1,1,1,1,1,1]"],"level4":["[1,1,1,4,0,0,0,0,0,1]","[1,1,1,1,1,1,1,0,0,1]","[1,1,0,0,0,0,1,0,0,1]","[1,0,0,0,0,0,1,0,0,1]","[1,0,0,1,1,0,0,3,0,1]","[1,0,0,0,0,0,2,0,2,1]","[1,0,0,0,0,0,0,0,0,1]","[1,0,0,1,0,0,1,1,1,1]"],"level5":["[1,1,1,1,0,0,1,0,1,1]","[1,1,1,4,0,0,0,0,1,1]","[1,1,1,2,0,0,0,1,1,1]","[1,1,1,0,1,1,0,2,1,1]","[1,1,3,0,0,1,0,0,1,1]","[1,1,0,0,0,0,0,0,1,1]","[1,1,1,0,0,0,0,0,1,1]","[1,1,1,0,1,1,0,0,1,1]"],"level6":["[1,1,1,1,1,1,1,1,1,1]","[1,1,1,1,0,0,0,0,4,1]","[1,1,1,1,1,1,0,0,0,0]","[1,1,1,1,0,0,0,0,0,3]","[1,1,1,1,0,0,0,0,0,0]","[1,1,1,1,0,2,0,0,0,0]","[1,1,1,1,1,1,0,0,0,0]","[1,1,1,1,1,1,0,0,1,1]"],"level7":["[1,1,1,1,1,0,0,0,0,4]","[1,1,0,0,0,0,0,0,0,2]","[1,1,0,0,0,0,1,1,0,0]","[1,1,0,0,0,0,0,1,0,0]","[1,1,0,0,0,0,0,0,2,0]","[1,1,0,0,0,1,0,0,2,0]","[1,1,0,0,3,0,0,0,2,0]","[1,1,1,1,1,1,1,0,0,0]"],"level8":["[0,0,0,0,0,0,0,1,1,1]","[0,1,1,1,0,0,0,4,0,0]","[0,1,0,0,0,0,0,0,1,0]","[0,2,0,0,0,0,0,0,1,0]","[2,2,0,1,0,0,0,0,1,0]","[1,1,0,0,0,0,0,0,0,0]","[1,3,0,0,0,0,0,0,0,1]","[1,0,0,1,1,0,0,0,1,1]"],"level9":["[4,2,0,0,0,0,0,0,0,0]","[1,1,1,1,1,1,1,1,1,0]","[0,0,0,0,0,0,0,0,0,2]","[0,1,1,1,1,1,1,1,1,1]","[2,0,0,0,0,0,0,0,0,0]","[1,1,1,1,1,1,1,1,1,0]","[3,0,0,0,0,0,0,0,0,2]","[1,1,1,1,1,1,1,1,1,1]"],"level10":["[1,1,0,0,0,0,0,0,0,4]",
"[1,1,0,1,1,0,0,0,1,2]",
"[1,1,0,2,0,0,1,1,1,0]",
"[1,1,0,0,0,0,1,0,0,3]",
"[1,1,0,1,0,0,0,0,0,0]",
"[1,1,0,1,0,0,0,1,0,0]",
"[1,1,0,1,0,1,0,1,1,1]",
"[1,1,0,1,0,0,0,0,0,2]"]
}

//读取

using LitJson;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;[Serializable]
public class LevelInfo
{public int[,] Levellist = new int[,] { };public int Wight { get; set; } //宽public int Height { get; set; } //高
}
public class LevelDate
{public static List<LevelInfo> GetLevel(){List<LevelInfo> LevelList = new List<LevelInfo>();TextAsset asset = Resources.Load<TextAsset>("Content/Levels");//Debug.Log(asset.text);JsonData data = JsonMapper.ToObject(asset.text);//Debug.Log(data.Count);for (int i = 0; i < data.Count; i++)//data.Count = 2{//JsonData data_1 = data[i];//Debug.Log(data[i].Count);LevelInfo levelinfo = new LevelInfo();List<string[]> Linshi = new List<string[]>();for (int j = 0; j < data[i].Count; j++) //data[i].Count = 8{//把读出来的第一列字符串的数字分割出来保存在Character_array数组里string[] Character_array = (data[i][j].ToString()).Split(new char[3] {'[',',',']'});Linshi.Add(Character_array);}//Debug.Log(Linshi.Count + "-----------");levelinfo.Height = Linshi.Count; //高levelinfo.Wight = Linshi[0].Length; //宽levelinfo.Levellist = new int[levelinfo.Height, levelinfo.Wight];for (int n = 0; n < Linshi.Count; n++) //levelinfo.Linshi.Count = 8{//为什么k = 1,k<levelinfo.Linshi[n].Length-1,因为前后有空格for (int k = 1; k < Linshi[n].Length-1; k++) // levelinfo.Linshi[n] = 10{//Debug.Log(Int32.Parse(Linshi[n][k]));levelinfo.Levellist[n, k - 1] = Int32.Parse(Linshi[n][k]);} }LevelList.Add(levelinfo);}return LevelList;}
}

这篇关于U3d-Json读取数组的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/897582

相关文章

Java 字符数组转字符串的常用方法

《Java字符数组转字符串的常用方法》文章总结了在Java中将字符数组转换为字符串的几种常用方法,包括使用String构造函数、String.valueOf()方法、StringBuilder以及A... 目录1. 使用String构造函数1.1 基本转换方法1.2 注意事项2. 使用String.valu

IDEA如何将String类型转json格式

《IDEA如何将String类型转json格式》在Java中,字符串字面量中的转义字符会被自动转换,但通过网络获取的字符串可能不会自动转换,为了解决IDEA无法识别JSON字符串的问题,可以在本地对字... 目录问题描述问题原因解决方案总结问题描述最近做项目需要使用Ai生成json,可生成String类型

Python中json文件和jsonl文件的区别小结

《Python中json文件和jsonl文件的区别小结》本文主要介绍了JSON和JSONL两种文件格式的区别,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下... 众所周知,jsON 文件是使用php JSON(JavaScripythonpt Object No

Java读取InfluxDB数据库的方法详解

《Java读取InfluxDB数据库的方法详解》本文介绍基于Java语言,读取InfluxDB数据库的方法,包括读取InfluxDB的所有数据库,以及指定数据库中的measurement、field、... 首先,创建一个Java项目,用于撰写代码。接下来,配置所需要的依赖;这里我们就选择可用于与Infl

使用Java解析JSON数据并提取特定字段的实现步骤(以提取mailNo为例)

《使用Java解析JSON数据并提取特定字段的实现步骤(以提取mailNo为例)》在现代软件开发中,处理JSON数据是一项非常常见的任务,无论是从API接口获取数据,还是将数据存储为JSON格式,解析... 目录1. 背景介绍1.1 jsON简介1.2 实际案例2. 准备工作2.1 环境搭建2.1.1 添加

C#读取本地网络配置信息全攻略分享

《C#读取本地网络配置信息全攻略分享》在当今数字化时代,网络已深度融入我们生活与工作的方方面面,对于软件开发而言,掌握本地计算机的网络配置信息显得尤为关键,而在C#编程的世界里,我们又该如何巧妙地读取... 目录一、引言二、C# 读取本地网络配置信息的基础准备2.1 引入关键命名空间2.2 理解核心类与方法

JAVA中整型数组、字符串数组、整型数和字符串 的创建与转换的方法

《JAVA中整型数组、字符串数组、整型数和字符串的创建与转换的方法》本文介绍了Java中字符串、字符数组和整型数组的创建方法,以及它们之间的转换方法,还详细讲解了字符串中的一些常用方法,如index... 目录一、字符串、字符数组和整型数组的创建1、字符串的创建方法1.1 通过引用字符数组来创建字符串1.2

SpringBoot使用Apache POI库读取Excel文件的操作详解

《SpringBoot使用ApachePOI库读取Excel文件的操作详解》在日常开发中,我们经常需要处理Excel文件中的数据,无论是从数据库导入数据、处理数据报表,还是批量生成数据,都可能会遇到... 目录项目背景依赖导入读取Excel模板的实现代码实现代码解析ExcelDemoInfoDTO 数据传输

Java解析JSON的六种方案

《Java解析JSON的六种方案》这篇文章介绍了6种JSON解析方案,包括Jackson、Gson、FastJSON、JsonPath、、手动解析,分别阐述了它们的功能特点、代码示例、高级功能、优缺点... 目录前言1. 使用 Jackson:业界标配功能特点代码示例高级功能优缺点2. 使用 Gson:轻量

Python读取TIF文件的两种方法实现

《Python读取TIF文件的两种方法实现》本文主要介绍了Python读取TIF文件的两种方法实现,包括使用tifffile库和Pillow库逐帧读取TIFF文件,具有一定的参考价值,感兴趣的可以了解... 目录方法 1:使用 tifffile 逐帧读取安装 tifffile:逐帧读取代码:方法 2:使用