The writing is not good, please forgive us.
1.Json format
{"Packages": [{"Type": "AAA"}], "Zone_packages": [{"TicketType": [{"Ticket_type": "111", "Ticket_count": "1", "Trans_ Num ": null," Refund_num ": null}]," Zone_group ":" Wuhan Garden Expo "," Ticket_key ":" 1753626040 "}]," ORDER_NBR ":" 30000000012015090800006524 "," Order_amount ":" "," order_nbr_original ":" 150908050106992 "," order_contacts ":" 仲秀萍 "," Contacts_tel ":" 15821311320 "," Order_remark ":" "," Use_date ":" 20150909 "," Order_status ":" 8 "}
2. Define extension methods
//<summary> split string becomes a name value dictionary </summary>
// <param name= "str" > </param> to split the string;
//<param name= " Namevalueseparator "> key-value pair delimiter </param>
//<param name=" Separators "> Split character </param>
//<returns> key-value pairs dictionary </ Returns>
public static idictionary<string, string> Splitasdictionary (This string str, string namevalueseparator = "=", params string[] separators)
& nbsp; {
var dic = new Dictionary<string, string> ();
if (string.isnullorwhitespace (str)) return DIC;
if (String.IsNullOrEmpty (namevalueseparator)) Namevalueseparator = "=";
if (separators = = NULL | | separators. Length < 1) separators = new string[] {",", ";"};
string[] ss = str. Split (separators, stringsplitoptions.removeemptyentries);
if (ss = = NULL | | ss. Length < 1) return null;
foreach (var item in SS)
{
Int32 p = Item. IndexOf (Namevalueseparator);
Not before or after.
if (P <= 0 | | p >= item. LENGTH-1) continue;
String key = Item. Substring (0, p). Trim ();
Dic[key] = Item. Substring (P + namevalueseparator.length). Trim ();
}
return dic;
}
3.Json Format parsing
public static Object Zoneticket (String json)
{
var doc = json;
JSON format parsing
var diclist = doc. Split (new string[] {"\" zone_packages\ ": [", "\" packages\ ": [", "\" tickettype\ ": [", "}]"}, Stringsplitoptions.none)
For each large class processing, first filter, then split into sub-class
. Select (n = n.replace ("\" "," "). Split (new string[] {"},{"}, Stringsplitoptions.none)
. Select (k = = K.replace ("{", "" "). Replace ("}", "")//Sub-class filtering
. Splitasdictionary (":", ","))//Extract the sub-class key-value pairs
. ToArray ()). ToList ();//List
return diclist;
}
(Multi-object) JSON converted to list