问题描述
- JavaScriptSerializer“ 没有为类型“System.String”定义无参数的构造函数”
-
JavaScriptSerializer c# 反序列化的时候报错“ 没有为类型“System.String”定义无参数的构造函数using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;using System.Web.Script.Serialization;
using System.Runtime.Serialization;namespace HLSX.Jason
{//[Serializable] public class ResultData { public ResultData() { } public ResultData(int res, string strda) { result = res; data = strda; } public int result { get; set; } public string data { get; set; } } class DealJson{ // ResultData rsData; public static int getResult( string strJson ) { ResultData rsData = new ResultData(); JavaScriptSerializer jsonSerializer = new JavaScriptSerializer(); rsData = jsonSerializer.Deserialize<ResultData>(strJson); return rsData.result; } public static string getData(string strJson) { ResultData rsData = new ResultData(); rsData.result = -2; rsData.data = string.Empty; JavaScriptSerializer jsonSerializer = new JavaScriptSerializer(); rsData = jsonSerializer.Deserialize<ResultData>(strJson);【此行报错】 return rsData.data; } }
}
解决方案
你把相关的类全部设置为可序列化的
时间: 2024-11-18 19:47:24