我得到一个有"场"字段的json.
如果"字段"有数据,那么有一个OBJECT有许多(大约20个)其他字段也是对象.我可以毫无问题地反序列化它们.
但是如果"field"没有数据,那么它就是一个空的ARRAY(我知道它很疯狂,但那是服务器的响应而我无法改变它).像这样的东西:
空的时候:
"extras":[
]
Run Code Online (Sandbox Code Playgroud)
有一些数据:
"extras": {
"22":{ "name":"some name" },
"59":{ "name":"some other name" },
and so on...
}
Run Code Online (Sandbox Code Playgroud)
所以,当没有数据(空数组)时,我显然得到了异常
Caused by: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException:
Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 4319
Run Code Online (Sandbox Code Playgroud)
我尝试使用自定义JavaDeserializer:
public class ExtrasAdapter implements JsonDeserializer<Extras> {
@Override
public Extras deserialize(JsonElement json, Type typeOf,
JsonDeserializationContext context) throws JsonParseException {
try {
JsonObject jsonObject = json.getAsJsonObject();
// deserialize normally
// the following does not work, as it makes recursive calls
// to the same …Run Code Online (Sandbox Code Playgroud) 如何使textview完全包装这样的文本?
android:width属性不是解决方案,因为文本是动态的.
期望的行为
|Adcs |
|adscfd|
Run Code Online (Sandbox Code Playgroud)
目前的行为:
|Adcs |
|adscfd |
Run Code Online (Sandbox Code Playgroud)
这里是代码(TextViews的样式只定义textColor,textSize,textStyle等).
<TextView
android:id="@+id/text_title_holder"
style="@style/TextBold.Black.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:maxWidth="100dp"
android:maxLines="2"
android:text="Adcs adscfd"
android:gravity="left"
android:visibility="visible" />
Run Code Online (Sandbox Code Playgroud)
mutiline TextView上的主题wrap_content宽度没有很好的答案.