Link to home
Start Free TrialLog in
Avatar of MohitPandit
MohitPanditFlag 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
ASKER CERTIFIED SOLUTION
Avatar of it_saige
it_saige
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 MohitPandit

ASKER

Thank you. I'll implement same at my end and let you know.
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
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-
Okay, I'll make change for removal of array and let you know

Best Regards
Thank you