StackOverflow Q25052293

CSharp · Console

/Program.cs

using System;
using System.Collections.Generic;
using Newtonsoft.Json;
					
public class Program
{
	public static void Main()
	{
		string json = @"
            {
                ""results"": {
                    ""jobcodes"": {
                        ""1"": {
                            ""_status_code"": 200,
                            ""_status_message"": ""Created"",
                            ""id"": 444444444,
                            ""assigned_to_all"": false,
                            ""billable"": true,
                            ""active"": true,
                            ""type"": ""regular"",
                            ""name"": ""1234 Main Street - Jackson""
                        },
                        ""2"": {
                            ""_status_code"": 200,
                            ""_status_message"": ""Created"",
                            ""id"": 1234567890,
                            ""assigned_to_all"": false,
                            ""billable"": true,
                            ""active"": true,
                            ""type"": ""regular"",
                            ""name"": ""4321 Some Other Street - Jackson""
                        }
                    }
                }
            }";
		
		RootObject obj = JsonConvert.DeserializeObject<RootObject>(json);
		
		foreach (KeyValuePair<string, JobCode> kvp in obj.Results.JobCodes)
		{
			Console.WriteLine("Id: " + kvp.Value.Id);
			Console.WriteLine("Name: " + kvp.Value.Name);
			Console.WriteLine("StatusCode: " + kvp.Value.StatusCode);
			Console.WriteLine("StatusMessage: " + kvp.Value.StatusMessage);
			Console.WriteLine();
		}
	}

	class RootObject
	{
		[JsonProperty("results")]
		public Results Results { get; set; }
	}
	
	class Results
	{
		[JsonProperty("jobcodes")]
		public Dictionary<string, JobCode> JobCodes { get; set; }
	}
	
	class JobCode
	{
		[JsonProperty("_status_code")]
		public string StatusCode { get; set; }
		[JsonProperty("_status_message")]
		public string StatusMessage { get; set; }
		[JsonProperty("id")]
		public string Id { get; set; }
		[JsonProperty("name")]
		public string Name { get; set; }
	}
}
;