0

Android アプリで Drupal サイト データを取得する正しい方法は何ですか?

30 ノードのデータを取得して、各行が layoutInflater を使用するリスト ビューにする必要があるとします。私の状況では、Json コードからデータを取得し、それらを配列に保存してから、データの各インデックスを listView 行に呼び出しています。これは正しい方法ですか?

7 つの配列を使用してデータを保持し、プロセスを続行するのは効率的ですか? かさばらず、柔軟性がない気がします。私は正しいですか?

編集:: JsonCode を追加

receivedJson = Json.getJsonString(Constants.HOST_DOMAIN_NAME
            + serviceEndPoint);

    try {

        /*
         * convert received Json String to Json array with
         * 
         * @getDrupalFinalJsonArray: METHOD
         */
        jsonArray = Json.getDrupalFinalJsonArray(receivedJson,
                objectParent, itemParent);
        /*
         * Define the length of @nodeBodyArray, @nodeAutherNameArray to be
         * the same length of sonArray but -1, since a factecus item added
         * at index(0) this ISSUE SHOULD BE SOLvER !
         */
        nodeTitleArray = new String[jsonArray.length() - 1];
        nodeAuthorNameArray = new String[jsonArray.length() - 1];
        nodeAuthorImageArray = new String[jsonArray.length() - 1];
        nodeCommentCount = new int[jsonArray.length() - 1];
        nodeNid = new int[jsonArray.length() - 1];
        postDate=new String[jsonArray.length()-1];

        nodeNid = Json.convertJsonArrayToIntJavaArray(jsonArray, "nid");
        nodeCommentCount = Json.convertJsonArrayToIntJavaArray(jsonArray,
                "commentcount");
        nodeTitleArray = Json.convertJsonArrayToStringJavaArray(jsonArray,
                "body");
        nodeAuthorNameArray = Json.convertJsonArrayToStringJavaArray(
                jsonArray, "author");
        nodeAuthorImageArray = Json.convertJsonArrayToStringJavaArray(
                jsonArray, "profile");
        postDate=Json.convertJsonArrayToStringJavaArray(jsonArray, Constants.NODE_POST_DATE_TAG);

    } catch (Exception e) {
    }
    adapter = new nodeListAdapter(context,
            android.R.layout.simple_list_item_1, nodeTitleArray,
            nodeAuthorNameArray, nodeAuthorImageArray, nodeCommentCount,
            nodeNid,postDate); // define the list adapter
4

1 に答える 1

0

title、nid、authorなどのフィールドを持つNodeクラスを作成することを提案します。そして、Jsonからノードを読み取るためのreadJsonメソッド。

例えば:

Node nodes[] = new Node[jsonArray.length() - 1];
for (int n = 0; n < jsonArray.length() - 2; n++) {
     nodes[n].readJson(jsonArray[n]);
}

Node.readJson実装がjson配列から値を取得し、それを適切なフィールドに設定している場合。

于 2013-02-17T06:22:17.303 に答える