Gson反序列化映射< K,V>由WCF休息服务序列化 [英] Gson deserialize Map<K,V> serialized by WCF Rest service
本文介绍了Gson反序列化映射< K,V>由WCF休息服务序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
{org.Mob ComplexObject @ 3dac2f9c:TAX1,org.Mob.ComplexObject@7369ca65:TAX2}
但是我的服务发送的json看起来像:
{Key:
{DefaultValue True,
描述:null,
DisplayName:自定义布尔值,
FieldType:0,
Id:6,
IsReadOnly:false,
IsRequired:false,
MaxLength:null,
Name:BoolVal,
ParamType:0}
Value:True},
{Key:
{DefaultValue:,
说明:null,
DisplayName :自定义文本,
FieldType:4,
Id:7,
IsReadOnly:false,
IsRequired:true,
MaxLength:16,
Name:TextVal,
ParamType:0},
Value:sda}
}
解另一种方法可能是添加了您自己的扩展ArrayList的Map / Dictionary实现,实际上是KVPair的列表,其中KVPair看起来像:
class KVPair< K,V> {
K Key;
V值;
}
我不知道它是否优雅,但在我的情况下工作。
I have a WCF Rest Service. I would like to use it from Android device. To do this I have chosen gson library. Everything seemed to work fine until I wanted to return from my service Object Containing Map. Gson serializes it (and as I am assuming also tries to deserialize from it) as something like:
{"org.Mob.ComplexObject@3dac2f9c":"TAX1","org.Mob.ComplexObject@7369ca65":"TAX2"}
But the json sent by my service looks like:
{"Key":
{"DefaultValue":"True",
"Description":null,
"DisplayName":"Custom Boolean",
"FieldType":0,
"Id":6,
"IsReadOnly":false,
"IsRequired":false,
"MaxLength":null,
"Name":"BoolVal",
"ParamType":0},
"Value":"True"},
{"Key":
{"DefaultValue":"",
"Description":null,
"DisplayName":"Custom Text",
"FieldType":4,
"Id":7,
"IsReadOnly":false,
"IsRequired":true,
"MaxLength":16,
"Name":"TextVal",
"ParamType":0},
"Value":"sda"}
}
解决方案
The other way to do it could be adding you own implementation of Map / Dictionary which extends ArrayList, and in fact is a List of KVPair, where KVPair looks like:
class KVPair<K,V>{
K Key;
V Value;
}
I don't know if it's elegant, but it worked in my case.
这篇关于Gson反序列化映射< K,V>由WCF休息服务序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文