【发布时间】:2013-07-16 20:09:36
【问题描述】:
我在尝试解码 Json 对象时遇到此错误
错误:类型“realstate.Models.PesquisaModel.pesquisaClienteListModel”不支持数组的反序列化。
这是字符串:
JSON 对象:
jsonObj=[{
"idCliente":"2",
"nome":"Guilherme Longo",
"email":"guilhermelongo@outlook.com.br",
"tipoPessoa":"1",
"observacao":"Mais conteúdo",
"rg":"435180307",
"cpf":"341.307.948-41",
"cnpj":null,
"estado":"SP",
"cidade":"Ribeirão Preto",
"logradouro":"Rua",
"endereco":"Brigadeiro Tobias de Aguiar",
"numero":"469",
"bairro":"Independência",
"complemento":"Bloco A"
},
{"idCliente":"8",
"nome":"Guilherme Longo",
...
}]
这是我遇到此错误的地方:
public ActionResult dataSetClientes(string jsonObj)
{
PesquisaModel.pesquisaClienteListModel items = new JavaScriptSerializer().Deserialize<PesquisaModel.pesquisaClienteListModel>(jsonObj);
...
}
编辑 1:
这是模型:
public class PesquisaModel
{
public class pesquisaClienteModel
{
public string idCliente { get; set; }
public string nome { get; set; }
public string email { get; set; }
public string tipoPessoa { get; set; }
public string observacao { get; set; }
public string rg { get; set; }
public string cpf { get; set; }
public string cnpj { get; set; }
public string estado { get; set; }
public string cidade { get; set; }
public string logradouro { get; set; }
public string endereco { get; set; }
public string numero { get; set; }
public string bairro { get; set; }
public string complemento { get; set; }
}
public class pesquisaClienteListModel
{
public List<pesquisaClienteModel> item { get; set; }
}
}
【问题讨论】:
-
抱歉这个可怜的问题。刚刚修好了。
-
你能调试它并将jsonObj字符串的内容发布到控制器端吗?
-
你是否传递了你的数据:JSON.stringfy(/*myDataToSend*/)?
-
@Fals 感谢您的所有回复。我没有将 JSON 对象转换为字符串。使用 JSON.stringfy(/*myDataToSend*/) 后,我能够在控制器中获取发布的数据。请张贴一个遮阳篷,以便我接受。
-
@GuilhermeLongo 欢迎您!我以 awnsear 的身份发布!
标签: c# json asp.net-mvc-4