Link to home
Start Free TrialLog in
Avatar of IzzyTwinkly
IzzyTwinklyFlag for United States of America

asked on

Parsing Json string with Json.net

Hi guys,

I have the following Json string:
[{"Key":"EmployeeType","Value":"Full"},{"Key":"ID","Value":"123456"}]

I create Employee class as follow:
public class Employee
{
        public KeyValuePair<string, string>[] Properties { get; set; }
}

And I called
Employee[] employees = JsonConvert.DeserializeObject<Employee[]>(JsonString);

Since I want it to be printed as
EmployeeType: Full
ID: 123456

so I used the following code:
foreach (var eID in employees)
             {
                 foreach (var item in eID.Properties)
                 {
                     Console.WriteLine("{0}: {1}", item.Key, item.Value);
                 }
             }

However, I am getting "NullReferenceException was unhandled" exception on foreach line.

Can anybody let me know how I can fix this issue?

Thanks!!!
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of IzzyTwinkly

ASKER

Thank you so much,  käµfm³d!
I really appreciate your help all the time.
NP. Glad to help  = )