
/// <summary>
/// 对象转json
/// </summary>
public static string ToJson(object jsonObject)
{
StringBuilder sb = new StringBuilder();
sb.Append("{"
);
PropertyInfo[] propertyInfo = jsonObject.GetType().GetProperties();
for (int i = 0; i < propertyInfo.Length; i++)
{
object objectValue = propertyInfo[i].GetGetMethod().Invoke(jsonObject, null);
Type type = propertyInfo[i].PropertyType;
string strValue = objectValue.ToString();
strValue = StringFormat(strValue, type);
sb.Append("\"" + propertyInfo[i].Name + "\":");
sb.Append(strValue + ",");
}
sb.Remove(sb.Length - 1, 1);
sb.Append("}");
return sb.ToString();
}

