-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJsonHelper.cs
53 lines (50 loc) · 1.58 KB
/
JsonHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using Newtonsoft.Json;
using System.Collections.Generic;
namespace RealAirplaneTag;
public class JsonHelper
{
/// <summary>
/// 将JSON字符串转换为字典。
/// </summary>
/// <param name="jsonString">要转换的JSON字符串。</param>
/// <returns>转换后的字典对象。</returns>
public static Dictionary<string, Dictionary<string, string>> ConvertJsonToDictionaryMap(string jsonString)
{
try
{
return JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, string>>>(jsonString);
}
catch (JsonReaderException ex)
{
// 处理解析异常,例如JSON格式错误
Console.WriteLine($"解析JSON时发生错误: {ex.Message}");
return null;
}
catch (Exception ex)
{
// 其他异常处理
Console.WriteLine($"发生未知错误: {ex.Message}");
return null;
}
}
public static Dictionary<string, string> ConvertJsonToDictionaryFlightNo(string jsonString)
{
try
{
return JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonString);
}
catch (JsonReaderException ex)
{
// 处理解析异常,例如JSON格式错误
Console.WriteLine($"解析JSON时发生错误: {ex.Message}");
return null;
}
catch (Exception ex)
{
// 其他异常处理
Console.WriteLine($"发生未知错误: {ex.Message}");
return null;
}
}
}