Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have any method with JSONArray like JSONObject.toJavaObject(Clazz<T> T)? #922

Closed
Andecy opened this issue Nov 25, 2016 · 1 comment
Closed
Milestone

Comments

@Andecy
Copy link

Andecy commented Nov 25, 2016

such as JSONArray.toJavaArray(Clazz T),like this:

@Override
public void onNext(JSONObject json) {
     List<Example> examples = json.getJSONObject("examples").toJavaArray(Example.class);
}
@wenshao wenshao added this to the 1.2.22 milestone Nov 27, 2016
@wenshao wenshao modified the milestones: 1.2.23, 1.2.22 Dec 10, 2016
@wenshao
Copy link
Member

wenshao commented Dec 20, 2016

public <T> List<T> toJavaList(Class<T> clazz) {
       List<T> list = new ArrayList<T>(this.size());

        ParserConfig config = ParserConfig.getGlobalInstance();

        for (Object item : this) {
            T classItem = (T) TypeUtils.cast(item, clazz, config);
            list.add(classItem);
        }

        return list;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants