Hi I am working on web API and getting the result on StreamReader. I want to convert these StreamReader to JSON I am using the Following code :
var response = (HttpWebResponse)request.GetResponse();
using (var stream = response.GetResponseStream())
using (var reader = new StreamReader(stream))
{
JavaScriptSerializer js = new JavaScriptSerializer();
var objText = reader.ReadToEnd();
MyObject myojb = (MyObject)js.Deserialize(objText, typeof(MyObject));
// Response.Write(reader.ReadToEnd());
}
And the actual Model schema is something like that
{
"id": "",
"description": "",
"added_date": "",
"media_type": "",
"contributor": {
"id": ""
},
"aspect": 0,
"image_type": "",
"is_editorial": false,
"is_adult": false,
"is_illustration": false,
"has_model_release": false,
"has_property_release": false,
"releases": [
""
],
"categories": [
{
"id": "",
"name": ""
}
],
"keywords": [
""
],
"assets": {
"small_jpg": {
"height": 0,
"width": 0,
"file_size": 0,
"display_name": "",
"dpi": 0,
"format": "",
"is_licensable": false
},
"medium_jpg": {
"height": 0,
"width": 0,
"file_size": 0,
"display_name": "",
"dpi": 0,
"format": "",
"is_licensable": false
},
"huge_jpg": {
"height": 0,
"width": 0,
"file_size": 0,
"display_name": "",
"dpi": 0,
"format": "",
"is_licensable": false
},
"supersize_jpg": {
"height": 0,
"width": 0,
"file_size": 0,
"display_name": "",
"dpi": 0,
"format": "",
"is_licensable": false
},
"huge_tiff": {
"height": 0,
"width": 0,
"file_size": 0,
"display_name": "",
"dpi": 0,
"format": "",
"is_licensable": false
},
"supersize_tiff": {
"height": 0,
"width": 0,
"file_size": 0,
"display_name": "",
"dpi": 0,
"format": "",
"is_licensable": false
},
"vector_eps": {
"height": 0,
"width": 0,
"file_size": 0,
"display_name": "",
"dpi": 0,
"format": "",
"is_licensable": false
},
"small_thumb": {
"url": "",
"height": 0,
"width": 0
},
"large_thumb": {
"url": "",
"height": 0,
"width": 0
},
"preview": {
"url": "",
"height": 0,
"width": 0
},
"preview_1000": {
"url": "",
"height": 0,
"width": 0
}
},
"models": [
{
"id": ""
}
]
}
And model is something like this
Image {
id (string),
description (string, optional),
added_date (string, optional),
media_type (string),
contributor (Contributor),
aspect (number, optional),
image_type (string, optional),
is_editorial (boolean, optional),
is_adult (boolean, optional),
is_illustration (boolean, optional),
has_model_release (boolean, optional),
has_property_release (boolean, optional),
releases (array[string], optional),
categories (array[Category], optional),
keywords (array[string], optional),
assets (ImageAssets, optional),
models (array[Model], optional)
}
Contributor {
id (string)
}
Category {
id (string, optional),
name (string, optional)
}
ImageAssets {
small_jpg (ImageSizeDetails, optional),
medium_jpg (ImageSizeDetails, optional),
huge_jpg (ImageSizeDetails, optional),
supersize_jpg (ImageSizeDetails, optional),
huge_tiff (ImageSizeDetails, optional),
supersize_tiff (ImageSizeDetails, optional),
vector_eps (ImageSizeDetails, optional),
small_thumb (Thumbnail, optional),
large_thumb (Thumbnail, optional),
preview (Thumbnail, optional),
preview_1000 (Thumbnail, optional)
}
ImageSizeDetails {
height (integer, optional),
width (integer, optional),
file_size (integer, optional),
display_name (string, optional),
dpi (integer, optional),
format (string, optional),
is_licensable (boolean, optional)
}
Thumbnail {
url (string),
height (integer),
width (integer)
}
Model {
id (string)
}
But i have no idea how do I create the Objects to get the JSON result.I am trying with the Myobject class but getting the error:
Type 'System.String' is not supported for deserialization of an array.
Please help how do i get the JSON result.Thanks in advance.