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

相关文章

hdu2241(二分+合并数组)

题意:判断是否存在a+b+c = x,a,b,c分别属于集合A,B,C 如果用暴力会超时,所以这里用到了数组合并,将b,c数组合并成d,d数组存的是b,c数组元素的和,然后对d数组进行二分就可以了 代码如下(附注释): #include<iostream>#include<algorithm>#include<cstring>#include<stack>#include<que

hdu 1166 敌兵布阵(树状数组 or 线段树)

题意是求一个线段的和,在线段上可以进行加减的修改。 树状数组的模板题。 代码: #include <stdio.h>#include <string.h>const int maxn = 50000 + 1;int c[maxn];int n;int lowbit(int x){return x & -x;}void add(int x, int num){while

C语言:柔性数组

数组定义 柔性数组 err int arr[0] = {0}; // ERROR 柔性数组 // 常见struct Test{int len;char arr[1024];} // 柔性数组struct Test{int len;char arr[0];}struct Test *t;t = malloc(sizeof(Test) + 11);strcpy(t->arr,

C 语言基础之数组

文章目录 什么是数组数组变量的声明多维数组 什么是数组 数组,顾名思义,就是一组数。 假如班上有 30 个同学,让你编程统计每个人的分数,求最高分、最低分、平均分等。如果不知道数组,你只能这样写代码: int ZhangSan_score = 95;int LiSi_score = 90;......int LiuDong_score = 100;int Zhou

matlab读取NC文件(含group)

matlab读取NC文件(含group): NC文件数据结构: 代码: % 打开 NetCDF 文件filename = 'your_file.nc'; % 替换为你的文件名% 使用 netcdf.open 函数打开文件ncid = netcdf.open(filename, 'NC_NOWRITE');% 查看文件中的组% 假设我们想读取名为 "group1" 的组groupName

计算数组的斜率,偏移,R2

模拟Excel中的R2的计算。         public bool fnCheckRear_R2(List<double[]> lRear, int iMinRear, int iMaxRear, ref double dR2)         {             bool bResult = true;             int n = 0;             dou

C# double[] 和Matlab数组MWArray[]转换

C# double[] 转换成MWArray[], 直接赋值就行             MWNumericArray[] ma = new MWNumericArray[4];             double[] dT = new double[] { 0 };             double[] dT1 = new double[] { 0,2 };

php中json_decode()和json_encode()

1.json_decode() json_decode (PHP 5 >= 5.2.0, PECL json >= 1.2.0) json_decode — 对 JSON 格式的字符串进行编码 说明 mixed json_decode ( string $json [, bool $assoc ] ) 接受一个 JSON 格式的字符串并且把它转换为 PHP 变量 参数 json

PHP7扩展开发之数组处理

前言 这次,我们将演示如何在PHP扩展中如何对数组进行处理。要实现的PHP代码如下: <?phpfunction array_concat ($arr, $prefix) {foreach($arr as $key => $val) {if (isset($prefix[$key]) && is_string($val) && is_string($prefix[$key])) {$arr[

Go 数组赋值问题

package mainimport "fmt"type Student struct {Name stringAge int}func main() {data := make(map[string]*Student)list := []Student{{Name:"a",Age:1},{Name:"b",Age:2},{Name:"c",Age:3},}// 错误 都指向了最后一个v// a