JSON.NET和Gson交互不好

时间:2013-12-28 12:48:25

标签: c# android json

我正在使用c#服务器连接adroid客户端。为了序列化信息我决定使用json。在c#方面是JSON.NET lib,在android上就是Gson lib。

当我从服务器序列化我的对象时,我获得了这个对我来说似乎没问题的输出:

{
  "Num_comunidad": "999",
  "Num_propietario": "0",
  "Nif": "123456789Q",
  "Razon": "BENITO TOCAMELA UNRATO",
  "Nombre": "",
  "Via": "",
  "Calle": "",
  "Num_calle": "0",
  "Piso": "",
  "Resto_domi": "",
  "Cod_pos": "00000",
  "Poblacion": "",
  "Provincia": "",
  "Tel1": "",
  "Tel2": "",
  "Tel3": "",
  "Fax": ""
}

当我检查android日志时,收到的字符串是:

12-28 20:10:25.799: I/System.out(1411): ########INPUT STRING: {

12-28 20:10:25.799: I/System.out(1411):   "Num_comunidad": "999",

12-28 20:10:25.809: I/System.out(1411):   "Num_propietario": "0",

12-28 20:10:25.809: I/System.out(1411):   "Nif": "123456789Q",

12-28 20:10:25.809: I/System.out(1411):   "Razon": "BENITO TOCAMELA UNRATO",

12-28 20:10:25.809: I/System.out(1411):   "Nombre": "",

12-28 20:10:25.809: I/System.out(1411):   "Via": "",

12-28 20:10:25.809: I/System.out(1411):   "Calle": "",

12-28 20:10:25.809: I/System.out(1411):   "Num_calle": "0",

12-28 20:10:25.809: I/System.out(1411):   "Piso": "",

12-28 20:10:25.809: I/System.out(1411):   "Resto_domi": "",

12-28 20:10:25.809: I/System.out(1411):   "Cod_pos": "00000",

12-28 20:10:25.809: I/System.out(1411):   "Poblacion": "",

12-28 20:10:25.809: I/System.out(1411):   "Provincia": "",

12-28 20:10:25.809: I/System.out(1411):   "Tel1": "",

12-28 20:10:25.819: I/System.out(1411):   "Tel2": "",

12-28 20:10:25.819: I/System.out(1411):   "Tel3": "",

12-28 20:10:25.819: I/System.out(1411):   "Fax": ""

12-28 20:10:25.819: I/System.out(1411): }

到目前为止,我认为这么好。但是当我反序列化它以获得一个对象时,这就是输出:

12-28 20:10:25.829: I/System.out(1411): ########GSON DESERIALIZATION: null|null|null|null|null|null|null|null|null|null|null|null|null|null|null|null|null

出于某种原因,它将所有属性都取为null,但它们不是。

c#侧的代码:

JsonConvert.SerializeObject(propietario, Formatting.Indented);

我甚至在没有指定格式的情况下尝试过。

android端的代码:

    System.out.println("########INPUT STRING: "+s);

    propietario = gson.fromJson(s, Propietario.class);

    System.out.println("########GSON DESERIALIZATION: "+propietario.toString());

有什么建议吗?

提前致谢!

0 个答案:

没有答案