如何使用C#将字符串转换为二维数组 [英] How Convert string into two dimensional array using c#
本文介绍了如何使用C#将字符串转换为二维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我在Java脚本中有一个二维数组,例如
Hi All,
I have a two dimensional array in java script like
var exArray = [[2, 3], [3, 4], [5, 6]];
这些数组值使用json对象存储在一个隐藏变量中.
These array values are stored in a hidden variable using json object.
document.getElementById("hdnArray").value = JSON.stringify(exArray);
在代码方面,
隐藏的变量值返回为"[[2,3],[3,4],[5,6]]".
现在,我想将这些隐藏变量值转换为二维数组而不使用拆分操作.
In Code side,
the hidden variable value return as "[[2, 3], [3, 4], [5, 6]]".
Now I want to convert these hidden variable value into two dimensional array without using spliting operation.
推荐答案
如果它是json编码的,则也可以在c#中使用相同的方法.使用json解串器.
[更新]
根据您要使用的功能,一种简单的方法是使用 FastJson [
If it is json encoded, you can use the same approach in c# also. Use a json deserializer.
[Update]
Depending on what you want to do with it, a simple method is using FastJson[^] for example:
var newobj = fastJSON.JSON.Instance.Parse(@"[[2, 3], [3, 4], [5, 6]]");
您将获得List< list< object>>.其中每个元素都是一个Int64.我不确定将其转换为数组是否确实必要.
You will get a List<list<object>> where every element will be an Int64. I am not sure, that converting this to array is really necessary.
这篇关于如何使用C#将字符串转换为二维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文