1
I am having difficulty deserializar a JSON. I am receiving the following content:
"response":{
"account":{
"name":"Evandro Teste",
"owners":[],
"creationDate":"2017-07-07T07:18PDT",
"city":"Guarulhos",
"description":"",
"state":"São Paulo",
"accountId":45,
"lastUpdated":"2017-07-07T07:18PDT",
"phone":"+55111231233",
"country":"",
"parentId":-1,
"industry":"Teste",
"address":"Rua Teste",
"relationshipUrls":{
"owners":"http://localhost/v1/object/account/45/owners",
"attachments":"http://localhost/v1/object/account/45/attachment",
"comment":"http://localhost/v1/object/account/45/comment",
"contactlog":"http://localhost/v1/object/account/45/contactlog",
"historylog":"http://localhost/api/v1/object/account/45/historylog"
}
}
},
"status":{
"success":true,
"detail":{}
}
My problem is how do I deserialize this JSON leaving aside the Sponse. That is, I need to create an object of type Account, ignoring the Answer (which returns in Json).
I’m using Restsharp and trying to do the same using also Javascriptserializer.
Follows below my entity:
public class Account
{
public string name { get; set; }
public string creationDate { get; set; }
public string city { get; set; }
public string description { get; set; }
public string state { get; set; }
public string fax { get; set; }
public int accountId { get; set; }
public string lastUpdated { get; set; }
public string mapQuest { get; set; }
public string phone { get; set; }
public string country { get; set; }
public int parentId { get; set; }
public string googleSearch { get; set; }
public string linkedInSearch { get; set; }
public string industry { get; set; }
public string address { get; set; }
public string AcctType { get; set; }
public string websiteURL { get; set; }
public string zipCode { get; set; }
}
what have you tried? what are the problems or difficulties encountered? Please provide more details.
– mercador
Oops, sorry. My problem is to convert the returned JSON that is up there in the Account object. On the return of the API call the.Data object is empty, however the Content object contains JSON. I’m trying for example: Javascriptserializer js = new Javascriptserializer(); var test = js.Deserialize<Account>(Answer.Content); var teste2 = js.Deserialize<Response>(Answer.Content); But when I do this my "test" and "teste2" object is resuming empty, but not error. Trying to use Restsharp.Deserializers.Jsondeserialize the same thing
– Evandro Sousa
Evandro and then the answer worked?
– novic
Yes. Thank you. How do I finish this topic?
– Evandro Sousa