2
I have this JSON
[{
"new_as_cod": "0010955",
"as_nome": "NAME",
"as_cpf": "1212121212",
"as_email": "[email protected]",
"as_cep": "88.025-200",
"igr_nome": "1\u00aa IGREJA BATISTA - FLORIANOPOLIS",
"id": "2781",
"valor": "50.00",
"pg_tipo_id": "CC",
"status": "Ativo",
"idstatus": "1"
}]
class was generated from from here
public class RootObject
{
public string new_as_cod { get; set; }
public string as_nome { get; set; }
public string as_cpf { get; set; }
public string as_email { get; set; }
public string as_cep { get; set; }
public string igr_nome { get; set; }
public string id { get; set; }
public string valor { get; set; }
public string pg_tipo_id { get; set; }
public string status { get; set; }
public string idstatus { get; set; }
}
I’ve been trying to use that expression.
RootObject data = JsonConvert.DeserializeObject<RootObject>(stringdate);
as_nome.Text = data.as_nome.ToString();
as_cpf.Text = data.as_cpf.ToString();
But you’re making this mistake.
An Exception of type 'Newtonsoft.Json.Jsonserializationexception' occurred in Newtonsoft.Json.DLL but was not handled in user code Additional information: Cannot deserialize the Current JSON array (e.g. [1,2,3]) into type 'Helloworldwp.Mainpage+Rootobject' because the type requires a JSON Object (e.g. {"name":"value"}) to deserialize correctly.
Dude, put up the Exception text and not a print of it.
– Jéf Bueno
An Exception of type 'Newtonsoft.Json.Jsonserializationexception' occurred in Newtonsoft.Json.DLL but was not handled in user code Additional information: Cannot deserialize the Current JSON array (e.g. [1,2,3]) into type 'Helloworldwp.Mainpage+Rootobject' because the type requires a JSON Object (e.g. {"name":"value"}) to deserialize correctly.
– Henrique Albuquerque
Henry, click [Edit] to edit your question. You can take the image and put the text of Exception, see the answer of @Onosendai, it is correct. By the way, welcome to [en.so]. See the [tour] and visit [help] to better understand how the site works.
– Jéf Bueno