string respDataJson = "A=&B=2&C=asdfasdf";
string respDataJson = "A=&B=2&C=asdfasdf";
var dddddd= StringToObject<ResponseModel>(respDataJson);
public static T StringToObject<T>(this string str) where T : new() { Type typeData = typeof(T); T entity = new T(); System.Reflection.PropertyInfo[] proArray = typeData.GetProperties(); var pairs = str.Split(‘&‘); foreach (var p in pairs) { var items = p.Split(‘=‘); if (items.Length == 2) { System.Reflection.PropertyInfo pro= proArray.Where(x => x.Name.ToUpper() == items[0].ToUpper()).FirstOrDefault(); if (pro != null) { pro.SetValue(entity, items[1], null); } } } return entity; }
public class ResponseModel
{
public string A { get; set; }
public string B { get; set; }
public string C { get; set; }
}