Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'Gnaritas.Coletor.Modelos.CampoFormularioColecao' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like
List<T>
that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.
Path '', line 1, position 1.
Estou desenvolvendo em C#
Minha classe que realiza desserialização:
public List<Coleta> SolicitarResumo()
{
List<CampoFormulario> dados = new List<CampoFormulario>();
dados.Add(new CampoFormulario(TokenService.ObterCodUser(), "usuar-sep") { dataType = "character", type = "input" });
//dados.Add(new CampoFormulario(DateTime.Today.ToShortDateString(), "data-sep") { type = "input", dataType = "datetime" });
CampoFormularioColecao campoColecao = new CampoFormularioColecao("valor");
campoColecao.type = "output";
campoColecao.value.fields.Add(new Field("cdd-embarq", "Codigo") { type = "integer" });
campoColecao.value.fields.Add(new Field("nome-abrev", "Cliente"));
campoColecao.value.fields.Add(new Field("vl-cliente", "Valor") { type = "decimal" });
dados.Add(campoColecao);
string dadosJson = JsonConvert.SerializeObject(dados);
callProcedureWithToken chamada = new callProcedureWithToken()
{
arg0 = TokenService.ObterToken(),
arg1 = "esp/esae0000.p",
arg2 = "pi-retorna-usuar-valor",
arg3 = dadosJson
};
callProcedureWithTokenResponse resposta = cliente.callProcedureWithToken(chamada);
CampoFormularioColecao registrosDicionario = JsonConvert.DeserializeObject<CampoFormularioColecao>(resposta.@return);
Tipo de dados para o qual desejo deserializar o json:
public class CampoFormularioColecao : CampoFormulario
{
public CampoFormularioColecao(string tipo)
{
dataType = "temptable";
name = "tt-lista-" + tipo;
value = new Value() { name = this.name };
}
public new Value value { get; set; }
}
public class Value
{
public Value()
{
fields = new List<Field>();
records = new List<JObject>();
}
public List<Field> fields { get; set; }
public List<JObject> records { get; set; }
public string name { get; set; }
}
public class Field
{
public Field(string pname, string plabel)
{
label = plabel;
name = pname;
type = "character";
}
public string name { get; set; }
public string label { get; set; }
public string type { get; set; }
}
Este é o Json que recebo:
[{
"dataType": "temptable",
"name": "tt-lista-valor",
"value": "{\"records\":[{\"vl-cliente\":240.12,\"cdd-embarq\":341647,\"nome-abrev\":\"MULT CHAVES\"},{\"vl-cliente\":1906.0,\"cdd-embarq\":341647,\"nome-abrev\":\"MULT CHAVES\"},{\"vl-cliente\":240.12,\"cdd-embarq\":341647,\"nome-abrev\":\"MULT CHAVES\"},{\"vl-cliente\":345.78,\"cdd-embarq\":341647,\"nome-abrev\":\"MULT CHAVES\"}],\"fields\":[{\"name\":\"cdd-embarq\",\"label\":\"Codigo\",\"type\":\"integer\"},{\"name\":\"nome-abrev\",\"label\":\"Cliente\",\"type\":\"character\"},{\"name\":\"vl-cliente\",\"label\":\"Valor\",\"type\":\"decimal\"}]}",
"type": "output"
}]
Parece que não reconhece o tipo CampoFormularioColecao ... Bem, como eu disse, sou novo aqui, peço desculpas se não fui suficientemente claro ou se eu pedisse algo trivial