Example usage for org.json JSONArray optInt

List of usage examples for org.json JSONArray optInt

Introduction

In this page you can find the example usage for org.json JSONArray optInt.

Prototype

public int optInt(int index) 

Source Link

Document

Get the optional int value associated with an index.

Usage

From source file:ru.rzn.myasoedov.vktest.dto.VKChat.java

@Override
public VKChat parse(JSONObject source) {
    try {/*w  ww .  j  a  v  a2 s  .  c  o m*/
        JSONObject message = source.getJSONObject("message");
        int chatId = message.getInt("chat_id");
        super.parse(message);
        id = chatId;
        preview = message.optString("body");
        date = message.optLong("date");
        photoUrl = message.optString("photo_50");
        JSONArray users = message.optJSONArray("chat_active");
        if (users != null) {
            this.users = new int[users.length()];
            for (int i = 0; i < this.users.length; i++) {
                this.users[i] = users.optInt(i);
            }
        }

    } catch (JSONException e) {
        return null;
    }
    return this;
}