您的位置:首页 > Web前端 > JavaScript

JSON使用MaxDepth反序列化设置最大深度

2015-12-11 15:01 453 查看
1.当反序列化时,使用MaxDepth指定最大深度,本例最大深度实际是3,但指定为2.即抛出异常.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using GongHuiNewtonsoft.Json;
using GongHuiNewtonsoft.Json.Serialization;
using GongHuiNewtonsoft.Json.Converters;

namespace JSONDemo
{
class Program
{
static void Main(string[] args)
{
try
{
JsonConvert.DeserializeObject<List<IList<IList<string>>>>(@"[
[
[
'3',
'Three',
'III'
]
]
]", new JsonSerializerSettings
{
MaxDepth = 2
//MaxDepth=3
});
}
catch (JsonReaderException ex)
{
Console.WriteLine(ex.Message);
}
}
}
}


2.运行的结果



JSON源代码下载地址:http://download.csdn.net/detail/lovegonghui/9342751
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: