需要使用到开源类库:Newtonsoft.Json,在visual studio中的NuGet包管理中可以下载。
首先添加引用:
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
下面是Json字符串的普通格式解析(json对象):
string str = @"{'pre_entry_id':'E20180012001120021','entry_id':'51192018019502145 (南海三山)','trade_code':'91440564616164L','trade_name':'淘宝','ie_port_code':'5304','ie_port':'蛇口海关','ex_date':'20180801','declare_date':'20181016','manual_no':'KK0000' }";
JObject jstr = (JObject)JsonConvert.DeserializeObject(str);
string prt = jstr["pre_entry_id"].ToString();
Console.WriteLine("pre_entry_id:{0}",prt);
输出结果:

同样json字符串解析(字典):
string str = @"{'pre_entry_id':'E20180012001120021','entry_id':'51192018019502145 (南海三山)','trade_code':'91440564616164L','trade_name':'淘宝','ie_port_code':'5304','ie_port':'蛇口海关','ex_date':'20180801','declare_date':'20181016','manual_no':'KK0000' }";
Dictionary<string, string> dic = JsonConvert.DeserializeObject<Dictionary<string, string>>(str);
string prt = dic["pre_entry_id"].ToString();
Console.WriteLine("pre_entry_id:{0}",prt);
Console.ReadKey();
输出结果:

浙公网安备 33010602011771号