Issue
I have a sample JSON file. How should I display this line by line, indention not required, on a textbox? Is it better to make a variable for every field?
{
"basics": {
"name": "Your first and last name",
"label": "",
"picture": "",
"email": "Your email address",
"phone": "A phone number, with any formatting you like. E.g. (555) 555-5555.",
"degree": "",
"website": "Your website URL",
"summary": "A one-sentence to one-paragraph overview text. Do not include any line-breaks.",
"location": {
"address": "Your street address or mailing address",
"postalCode": "Your postal code (ZIP in the U.S.)",
"city": "Your city",
"countryCode": "Your country (e.g. USA)",
"region": "Your region (state in the U.S.)"
},
"profiles": [
{
"network": "A social media or other profile that you would like to include (e.g. LinkedIn, Twitter)",
"username": "Your username on this network",
"url": "A URL to your user profile page"
}
]
},
Solution
Create a class for the JSON. https://json2csharp.com/
public class Basics
{
public string name { get; set; }
public string label { get; set; }
public string picture { get; set; }
public string email { get; set; }
public string phone { get; set; }
public string degree { get; set; }
public string website { get; set; }
public string summary { get; set; }
public Location location { get; set; }
public List<Profile> profiles { get; set; }
}
public class Location
{
public string address { get; set; }
public string postalCode { get; set; }
public string city { get; set; }
public string countryCode { get; set; }
public string region { get; set; }
}
public class Profile
{
public string network { get; set; }
public string username { get; set; }
public string url { get; set; }
}
public class Root
{
public Basics basics { get; set; }
}
You have to Deserialized the JSON before you can use it.
Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse)
Answered By - lenard backup Answer Checked By - Senaida (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.