How to convert single string to JsonArray in android?

前端 未结 2 475
时光说笑
时光说笑 2021-01-25 00:08

I need to convert a String[] to an JsonArray and I don\'t know how. I am new in android development i want to insert call log details in MySQL database. so, from android side i

2条回答
  •  温柔的废话
    2021-01-25 00:35

    Try this,

    // Create JSONArray
    JSONArray jArray = new JSONArray();
    while (managedCursor.moveToNext())
    {
        final String number = managedCursor.getString(number1);
        final String type2 = managedCursor.getString(type1);
        final String date = managedCursor.getString(managedCursor.getColumnIndexOrThrow("date")).toString();
        Date date1 = new Date(Long.valueOf(date));
        final String fDate = date1.toString();
        final String duration = managedCursor.getString(duration1);
        String type = null;
    
        // Create JSONObject
        JSONObject item = new JSONObject();
    
        // add the items to JSONObject
        item.put("number", number);
        item.put("type2", type2);
        item.put("fDate", fDate);
        item.put("duration", duration);
    
        // add the JSONObject to JSONArray
        jArray.put(item);
    }
    managedCursor.close();
    
    System.out.println(jArray.toString());
    

提交回复
热议问题