2012-07-18 19 views
0

在Android應用中檢索Drupal站點數據的正確方法是什麼?從Drupal站點檢索數據到Android應用的最佳方式

讓我們說我需要將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 
+0

顯示JSON .. – 2012-07-19 00:10:49

回答

0

我建議把與標題,NID,作者等領域Node類。 用於從Json讀取Node的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數組獲取值並將其設置爲相應的字段。

相關問題