C# - Converting JSON to C# Array -
i new c# , have little problem. have json-file includes mailadresses. each mailadress there 4 fields (name, email[], imprint, info2) in json-file. want convert array or arraylist in project , using newtonsoft.json achieve this.
i made class adress :
public class adress { public string name = ""; public string[] email = {""}; public string imprint = ""; public string info2 = ""; }
this json:
{"name":"test1","email":["test1@test.de"],"imprint":"testimprint1 testimprint1","info2":"testinfo1"} {"name":"test2","email":["test2@test.de"],"imprint":"testimprint2 testimprint2","info2":"testinfo2"} {"name":"test3","email":["test3@test.de"],"imprint":"testimprint3 testimprint3","info2":"testinfo3"}
and try converting this:
list<adress> adresses = new list<adress>(); string json_adress = file.readalltext("c:\\mail\\adresses.json"); adresses = jsonconvert.deserializeobject<list<adress>>(json_adress);
i following error:
"cannot deserialize current json object (e.g. {"name":"value"}) type 'system.collections.generic.list1[mailer.adress]' because type requires json array (e.g. [1,2,3]) deserialize correctly."`
maybe can me understand json-thing better?
you there small mistake. supplied following. please take notice there no commas @ seperation.
{jsonstuff} {jsonstuff} {jsonstuff}
but following says want converted list<address>
not list :(
jsonconvert.deserializeobject<list<adress>>(json_adress);
so in fact need supply list of address,
[ {jsonstuff}, {jsonstuff}, {jsonstuff}, ]
please not forget commas :)
[{"name":"test1","email":["test1@test.de"],"imprint":"testimprint1 testimprint1","info2":"testinfo1"}, {"name":"test2","email":["test2@test.de"],"imprint":"testimprint2 testimprint2","info2":"testinfo2"}, {"name":"test3","email":["test3@test.de"],"imprint":"testimprint3 testimprint3","info2":"testinfo3"}]
Comments
Post a Comment