0

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"
      }
    ]
  },
2
  • What have you tried? What didn't work and why? Commented Jul 7, 2022 at 12:26
  • JSON content is just a string so you can just use it to fill the innerText of a textarea or any other html element. But you are actually talking about winforms.. yet the comment is still pretty valid Commented Jul 7, 2022 at 12:27

1 Answer 1

0

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)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.