c# - json deserialization error -


im getting error while trying deserialize json string object :

    "system.web.services.protocols.soapexception: server unable process request. ---> newtonsoft.json.jsonserializationexception: error converting value "{"admin":false,"id":1,"password":"heslo","nick":"jozifek"}" type 'entities.dbo.user'. path 'frontman', line 1, position 105. ---> system.argumentexception: not cast or convert system.string entities.dbo.user.    @ newtonsoft.json.utilities.convertutils.ensuretypeassignable(object value, type initialtype, type targettype)    @ newtonsoft.json.utilities.convertutils.convertorcast(object initialvalue, cultureinfo culture, type targettype)    @ newtonsoft.json.serialization.jsonserializerinternalreader.ensuretype(jsonreader reader, object value, cultureinfo culture, jsoncontract contract, type targettype)    --- end of inner exception stack trace ---    @ newtonsoft.json.serialization.jsonserializerinternalreader.ensuretype(jsonreader reader, object value, cultureinfo culture, jsoncontract contract, type targettype)    @ newtonsoft.json.serialization.jsonserializerinternalreader.createvalueinternal(jsonreader reader, type objecttype, jsoncontract contract, jsonproperty member, jsoncontainercontract containercontract, jsonproperty containermember, object existingvalue)    @ newtonsoft.json.serialization.jsonserializerinternalreader.setpropertyvalue(jsonproperty property, jsonconverter propertyconverter, jsoncontainercontract containercontract, jsonproperty containerproperty, jsonreader reader, object target)    @ newtonsoft.json.serialization.jsonserializerinternalreader.populateobject(object newobject, jsonreader reader, jsonobjectcontract contract, jsonproperty member, string id)    @ newtonsoft.json.serialization.jsonserializerinternalreader.createobject(jsonreader reader, type objecttype, jsoncontract contract, jsonproperty member, jsoncontainercontract containercontract, jsonproperty containermember, object existingvalue)    @ newtonsoft.json.serialization.jsonserializerinternalreader.createvalueinternal(jsonreader reader, type objecttype, jsoncontract contract, jsonproperty member, jsoncontainercontract containercontract, jsonproperty containermember, object existingvalue)    @ newtonsoft.json.serialization.jsonserializerinternalreader.deserialize(jsonreader reader, type objecttype, boolean checkadditionalcontent)    @ newtonsoft.json.jsonserializer.deserializeinternal(jsonreader reader, type objecttype)    @ newtonsoft.json.jsonconvert.deserializeobject(string value, type type, jsonserializersettings settings)    @ newtonsoft.json.jsonconvert.deserializeobject(string value, type type)    @ bussinesslogic.helpers.serializer.deserialize[t](string obj) in c:\users\ondra\documents\visual studio 2010\projects\webservicetestapp\bussinesslogic\helpers\serializer.cs:line 14    @ webservicetestapp.service1.getsongs(string band) in c:\users\ondra\documents\visual studio 2010\projects\webservicetestapp\webservicetestapp\service1.asmx.cs:line 142    --- end of inner exception stack trace ---" 

user.cs looks this:

namespace entities.dbo {     [tablename("tbl_user")]     public class user : abstractentity     {         [mapfield("nick")]         public string nick { get; set; }          [mapfield("password")]         public string password { get; set; }          [mapfield("admin")]         public bool admin { get; set; }     } } 

and band.cs looks this:

namespace entities.dbo {     [tablename("tbl_band")]     public class band : abstractentity     {         [mapfield("name")]         public string name { get; set; }          [mapfield("frontman")]         public int frontmanid { get; set; }          [association(canbenull = false, thiskey = "frontmanid", otherkey = "id")]         public user frontman { get; set; } 

abstractentity:

namespace entities.helpers {     public abstract class abstractentity     {         [primarykey, identity, mapfield("id")]         public int id { get; set; }          public string serialize()         {             return jsonconvert.serializeobject(this);         }     } } 

and error pops out when im sending string deserialize band containing user object in frontman property..

any idea went wrong?

thanks :)

its hard say, have use jonson once few years ago, but

  1. in jonson have property "password" in object have mapfield("password") - in lower case

  2. is in abstractentity class "id" property?


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -