"[{\"active\":true,\"campaignId\":11401,\"createdtime\":1355919181000,\"description\":\"Ankit Demo Edited By Nirav\",\"enddate\":1363132800000,\"groupId\":10179,\"isdeleted\":false,\"lastmodifiedby\":10405,\"modifiedtime\":1362556187000,\"name\":\"Ankit Demo\",\"noofweek\":12,\"organizationId\":11153,\"startdate\":1355875200000,\"status\":2,\"userId\":11161},
{\"active\":true,\"campaignId\":21901,\"createdtime\":1358493958000,\"description\":\"sdadadasd\",\"enddate\":1359072000000,\"groupId\":10179,\"isdeleted\":false,\"lastmodifiedby\":10405,\"modifiedtime\":1358751277000,\"name\":\"NEW CAMP TEST\",\"noofweek\":1,\"organizationId\":10707,\"startdate\":1358467200000,\"status\":4,\"userId\":10405},
{\"active\":true,\"campaignId\":33601,\"createdtime\":1361441582000,\"description\":\"dasdsadasd\",\"enddate\":1363219200000,\"groupId\":10179,\"isdeleted\":false,\"lastmodifiedby\":10405,\"modifiedtime\":1361795632000,\"name\":\"BHAVIK UTC\",\"noofweek\":3,\"organizationId\":10707,\"startdate\":1361404800000,\"status\":2,\"userId\":10405}]"
文字列変数にJsong文字列の上があります..そして、このjson文字列をカスタムクラスのオブジェクトに変換したい..カスタムクラスを作成しました..以下は、HttpWebResponseからjsonで応答を取得するコードですカスタムクラスのリストオブジェクトで変換する
HttpWebResponse response = default(HttpWebResponse);
try
{
response = (HttpWebResponse)request.GetResponse();
// response.Close()
string sResult = null;
using (StreamReader responseReader = new StreamReader(response.GetResponseStream()))
{
sResult = responseReader.ReadToEnd();
}
response.Close();
Console.WriteLine(sResult);
List<Class1> myDeserializedObjList = (List<Class1>)Newtonsoft.Json.JsonConvert.DeserializeObject(Request[sResult], typeof(List<Class1>));
int counts= myDeserializedObjList.Count;
}
しかし、それは私にエラーを与えます
Value cannot be null.
Parameter name: s
誰でもこの問題を解決する方法を教えてもらえますか?
これは、システムを使用してjson文字列からオブジェクトを割り当てたいカスタムクラスです。System.Collections.Generic の使用; System.Linq を使用します。System.Web の使用;
/// <summary>
/// Summary description for Class1
/// </summary>
public class Class1
{
private Boolean active;
public Boolean Active
{
get { return active; }
set { active = value; }
}
private long campaignId;
public long CampaignId
{
get { return campaignId; }
set { campaignId = value; }
}
private long createdtime;
public long Createdtime
{
get { return createdtime; }
set { createdtime = value; }
}
private string description;
public string Description
{
get { return description; }
set { description = value; }
}
private long enddate;
public long Enddate
{
get { return enddate; }
set { enddate = value; }
}
private long groupId;
public long GroupId
{
get { return groupId; }
set { groupId = value; }
}
private Boolean isdeleted;
public Boolean Isdeleted
{
get { return isdeleted; }
set { isdeleted = value; }
}
private long modifiedtime;
public long Modifiedtime
{
get { return modifiedtime; }
set { modifiedtime = value; }
}
private long lastmodifiedby;
public long Lastmodifiedby
{
get { return lastmodifiedby; }
set { lastmodifiedby = value; }
}
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
private int noofweek;
public int Noofweek
{
get { return noofweek; }
set { noofweek = value; }
}
private long organizationId;
public long OrganizationId
{
get { return organizationId; }
set { organizationId = value; }
}
private long startdate;
public long Startdate
{
get { return startdate; }
set { startdate = value; }
}
private Boolean status;
public Boolean Status
{
get { return status; }
set { status = value; }
}
private long userId;
public long UserId
{
get { return userId; }
set { userId = value; }
}
public Class1()
{
}
}