0

I Have very specific requirement for this android app, Where I get JSON file from server Like this:

[
{"st":"f","t":"PDF","tbico":"107-widescreen.png","f":"PG033%20-%20Blue%20on%20Black.pdf"},
{"t":"Call","tbico":"BG092.png","dialNumBtn":"1231231234","st":"dialNumBtn"},
{"t":"Facebook Photos","tbico":"113navigation.png","fbPgID":"zoo"}
]

In pre-built iOS version of this app, Layout will look something like this link using above JSON , And I have a task to use this JSON and display it similar way in android (Using TabView) for Example this link My problem is: How can i create different Tabs and Fragments Activity that will adjust it self according to above json (e.g: In case if there is one more object in above JSON, than show one more Tab in Layout)?

This did not help me: link, I have parse json and stuff, I need help with How to displaying UI element

4

1 回答 1

1

您在这里需要一些严肃的 JSON 库,例如Jackson

创建你的基类(警告:伪代码,适应),这样你就有了,说:

@JsonIgnoreProperties(ignoreUnknown = true)
public abstract class MyBaseClass
{
    @JsonProperty("t")
    protected String title;
    @JsonProperty("tbico")
    protected final String iconName;

    // etc
}

然后扩展MyBaseClass以便为每个选项卡类型创建一个对象。

反序列化它使用:

// customize as needed, see javadoc
final ObjectMapper mapper = new ObjectMapper();
final List<MyBaseClass> l = mapper.readValue(theJson, 
    new TypeReference<List<MyBaseClass>>() {});

要么这个,要么走 JSON(使用 JsonNode 这太棒了)并一个一个地创建你的标签。

于 2013-07-10T06:40:22.983 回答