Avatar of MohitPandit
MohitPandit
Flag for India asked on

.NET: How to pass typed serialize using JavaScriptSerializer ==> Deserialize in C#

Hello,

I've JSON. Could you assist how to create C# class & pass typed class object in JSON deserialize so that I can get First Name, Last Name & Phone number in array?

I've JSON output in this format

  1. JSON root
HeaderResponse
Response
documents

The data type respectively as below:

1. {} HeaderResponse
i.) Status (integer)
ii.) TimeStamp (integer)

2. {} Response
i.) Number (integer)
ii.) Start (integer)

3. Under (Response)
i.) [documents
With multiple rows like
a.) First Name (string)
b.) Last Name (string)
c.) [] Phone number (string), but can be multiple

Best Regards
JSON.NET ProgrammingC#

Avatar of undefined
Last Comment
MohitPandit

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
it_saige

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
MohitPandit

ASKER
Thank you. I'll implement same at my end and let you know.
MohitPandit

ASKER
I implemented same. Once, I got JSON string and pass to JavaScriptSerializer. It is giving me below error:


No parameterless constructor defined for type of 'MyPOCName.Form1+ServiceResponse[]

Please find below code, where it is giving an error:

JavaScriptSerializer sr = new JavaScriptSerializer();
jsonResponse = sr.Deserialize<ServiceResponse[]>(jsonString);

Open in new window


Could you check once?

Best Regards
it_saige

First, I am using the Newtonsoft library in order to parse the json (IMHO, provides a more robust and complete solution for converting json objects to c# objects).

Second, you are trying to convert a singular json result into an array of json results.

-saige-
Your help has saved me hundreds of hours of internet surfing.
fblack61
MohitPandit

ASKER
Okay, I'll make change for removal of array and let you know

Best Regards
MohitPandit

ASKER
Thank you