MohitPandit
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
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
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
- 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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I implemented same. Once, I got JSON string and pass to JavaScriptSerializer. It is giving me below error:
Please find below code, where it is giving an error:
Could you check once?
Best Regards
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);
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-
Second, you are trying to convert a singular json result into an array of json results.
-saige-
ASKER
Okay, I'll make change for removal of array and let you know
Best Regards
Best Regards
ASKER
Thank you
ASKER