I'm having trouble deserializing an JSON string to a class I wrote.
Here are my Classes
class Newsletter
{
public string id;
public string state;
public string html;
public string name;
}
class ApiReply
{
int success;
//string value;
int status;
string reason;
}
class Newsletterlist : ApiReply
{
private const string URL = "https://www.newsletter2go.de/de/api/get/newsletters/";
public string key { private set; get; }
public Newsletterlist()
{
key = "MYAPIKEY";
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(URL);
httpWebRequest.ContentType = "application/x-www-form-urlencoded";
httpWebRequest.Method = "POST";
byte[] data = PostData.get_postData(this);
httpWebRequest.ContentLength = data.Length;
using (var stream = httpWebRequest.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
var response = (HttpWebResponse)httpWebRequest.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
dynamic temp = JsonConvert.DeserializeObject(responseString);
}
public List<Newsletter> value {private set;get;}
}
I want to deserialize the JSON Return String into my Object Newsletterlist,
but inside the JSON String, there's an JSON Array and I don't know how to deserialize the JSON Array to List<Newsletter> Value.
The JSON String looks something like this:
{
success : 0,
value : [], <-- Value may contain a JSON Array which I want to Serialize to List<Newsletter>
status :405,
reason : “Method Not Allowed , POST Required”
}
List<string>if its a complex type then create an object that matches it and have aList<ComplexType>