今天趁着看源代码的同时,记录学习的小知识。

一、String.Split 方法有6个重载函数:

1) public string[] Split(params char[] separator)
2) public string[] Split(char[] separator, int count)
3) public string[] Split(char[] separator, StringSplitOptions options)
4) public string[] Split(string[] separator, StringSplitOptions options)
5) public string[] Split(char[] separator, int count, StringSplitOptions options)
6) public string[] Split(string[] separator, int count, StringSplitOptions options)

下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):

1. public string[] Split(params char[] separator)

返回值:

类型:System.String[]
一个数组,其元素包含此实例中的子字符串,这些子字符串由 separator 中的一个或多个字符分隔。 有关更多信息,请参见“备注”一节。 

string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}

2. public string[] Split(char[] separator, int count)

string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}

3. public string[] Split(char[] separator, StringSplitOptions options)

string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素

4. public string[] Split(string[] separator, StringSplitOptions options)

string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素

5. public string[] Split(char[] separator, int count, StringSplitOptions options)

string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素

6. public string[] Split(string[] separator, int count, StringSplitOptions options)

string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素

需要注意的是没有重载函数public string[] Split(string[] separator),所以我们不能像VB.NET那样使用words.Split(","),而只能使用words.Split(',')!很多人都很奇怪为什么把双引号改为单引号就可以了?看了上边的重载函数该知道答案了吧^_^

二、JSON.stringify 函数

将 JavaScript 转换为 JavaScript 对象表示法 (JSON) 字符串。

JSON.stringify(value [, replacer] [, space])

Converts a JavaScript value to a JavaScript Object Notation (JSON) string.

Parameters:

value

Required. A JavaScript value, usually an object or array, to be converted.

replacer

Optional. A function or array that transforms the results.

If replacer is a function, JSON.stringify calls the function, passing in the key and value of each member. The return value is used instead of the original value. If the function returns undefined, the member is excluded. The key for the root object is an empty string: "".

If replacer is an array, only members with key values in the array will be converted. The order in which the members are converted is the same as the order of the keys in the array. The replacer array is ignored when the value argument is also an array.

space

Optional. Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.

If space is omitted, the return-value text is generated without any extra white space.

If space is a number, the return-value text is indented with the specified number of white spaces at each level. If space is greater than 10, text is indented 10 spaces.

If space is a non-empty string, such as '\t', the return-value text is indented with the characters in the string at each level.

If space is a string that is longer than 10 characters, the first 10 characters are use。

Example:

var contact = new Object();
contact.firstname = "Jesper";
contact.surname = "Aaberg";
contact.phone = ["555-0100", "555-0120"]; var memberfilter = new Array();
memberfilter[0] = "surname";
memberfilter[1] = "phone";
var jsonText = JSON.stringify(contact, memberfilter, "\t");
document.write(jsonText);
// Output:
// { "surname": "Aaberg", "phone": [ "555-0100", "555-0120" ] }

三、DeserializeObject 方法

public Object DeserializeObject(
string input

参数

input
类型:System.String
要进行反序列化的 JSON 字符串。

返回值

类型:System.Object
反序列化的对象。


Json与数组的更多相关文章

  1. json在php中的使用之如何转换json为数组

    <?php $json = '{"a":1,"b":2,"c":3,"d":4,"e":5}' ...

  2. MVC中用ajax提交json对象数组

    应用场景:在前端用ajax向服务器提交json对象数组,在controller的以对象数组作为函数的参数,提交的json数组直接转为服务器端的对象数组. 如: 要将json对象数组[{Id:1,Nam ...

  3. list对象数组,xpath复杂定位校验,POST入参为number数组,POST入参为JSON对象数组

    list对象数组: POST入参为number数组: {    "typeIds":[1,2,3]} POST入参为JSON对象数组,举例: [{    "itemId& ...

  4. javascript:Json 和数组的遍历

    首先看代码示例var json={a:1,b:2,c:3}; //json var array={1,2,3}; //数组 alert(json.a); //弹出1 或alert(json['a']) ...

  5. spring MVC 如何接收前台传入的JSON对象数组并处理

    spring MVC 如何接收前台传入的JSON对象数组 主要方法: (主要用到的包是 net.sf.json  即:json-lib-2.3-jdk15.jar 完整相关jar包: commons- ...

  6. json和数组的区别

    原文地址:https://www.cnblogs.com/zhangjingyun/p/4554054.html 我们都知道,json和数组一样,都可以存数据,但是下面我们来总结一下json和数组的区 ...

  7. spring MVC 如何接收前台传入的JSON对象数组

    spring MVC 如何接收前台传入的JSON对象数组 主要方法: (主要用到的包是 net.sf.json  即:json-lib-2.3-jdk15.jar 完整相关jar包: commons- ...

  8. js 数组、对象转json 以及 json转 数组、对象

    let jsonObj = $.parseJSON(jsonStr); //json字符串转化成json对象(jq方法) var jsonObj = JSON.parse(jsonStr); //js ...

  9. 将Json对象数组转化成JS Array数组

    private format(cards:any):Array<any>{ var result = new Array(); cards.forEach(element => { ...

  10. C# Newtonsoft.Json解析数组的小例子[转]

    https://blog.csdn.net/Sayesan/article/details/79756738 C# Newtonsoft.Json解析数组的小例子  http://www.cnblog ...

随机推荐

  1. List多个字段标识过滤

    class Program {  public static void Main(string[] args) { List<T> list = new List<T>(); ...

  2. 关于python 中的 sys.argv 的使用方法

    sys.argv是获取在cmd运行python文件的时候输入的命令行参数,呈现的数据结构是列表的格式 1.用pacharm时运行时的结果是: 输出结果: 2.当我在cmd中输入指令      debu ...

  3. 构造矩阵解决这个问题 【nyoj299 Matrix Power Series】

    矩阵的又一个新使用方法,构造矩阵进行高速幂. 比方拿 nyoj299 Matrix Power Series 来说 给出这样一个递推式: S = A + A2 + A3 + - + Ak. 让你求s. ...

  4. Windows服务操作之sc和net命令及windows任务计划

    看个粟子: 1.“新建项目”——“Window服务” 生成的目录结构 双击“MainService.cs”,右键点击“添加安装程序”,自动会生成Projectinstaller.cs文件以及两个安装组 ...

  5. spring in action 8.1 使用Spring web flow

    一.说明 Spring Web Flow是spring MVC的扩展,它支持基于流程的应用程序,他将流程的定义和实现流程行为的类和视图分离开来. 1.1 spring中配置web flow,目前需要在 ...

  6. 将SVM用于多类分类

    转自:http://www.lining0806.com/%E5%B0%86svm%E7%94%A8%E4%BA%8E%E5%A4%9A%E7%B1%BB%E5%88%86%E7%B1%BB/ SVM ...

  7. CentOS Linux防火墙配置及关闭

    CentOS 配置防火墙操作实例(启.停.开.闭端口): 注:防火墙的基本操作命令: 查询防火墙状态: [root@localhost ~]# service   iptables status< ...

  8. Java中path,-classpath,-Djava.library.path的功能和区别

    1. path path是个系统环境变量,声明命令的搜索路径,让操作系统找到指定的工具程序. D:\Program Files\Java\jdk1.8.0_111\bin指定JDK工具路径,例如jav ...

  9. atitit.软件gui按钮and面板---os区-----软链接,快捷方式

    atitit.软件gui按钮and面板---os区-----软链接,快捷方式 1. 硬链接 1 2. 二.软链接(符号链接)LN 1 3. 三.删除链接 2 4. 区别 2 5. 参考 3 1. 硬链 ...

  10. redis基础之安装和配置(一)

    前言 折腾一下redis在linux环境的安装. ubantu16.04环境下安装 下载安装,依次执行命令; # 从官方网站下载安装包,注意,当前在哪个目录下执行命令,下载的包将在哪个目录下 $ wg ...