Android JSON Insert insertJSONArrayContent( ContentResolver contentResolver, Uri uri, JSONArray array)

Here you can find the source of insertJSONArrayContent( ContentResolver contentResolver, Uri uri, JSONArray array)

Description

insert JSON Array Content

Declaration

public static void insertJSONArrayContent(
            ContentResolver contentResolver, Uri uri, JSONArray array)
            throws JSONException 

Method Source Code

//package com.java2s;

import java.util.Iterator;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.content.ContentResolver;
import android.content.ContentValues;

import android.net.Uri;

import android.util.Log;

public class Main {
    public static void insertJSONArrayContent(
            ContentResolver contentResolver, Uri uri, JSONArray array)
            throws JSONException {
        Log.i("uri", uri.toString());
        for (int i = 0; i < array.length(); i++) {
            //Log.i("i",array.getJSONObject(i).toString());
            insertJSONObjectContent(contentResolver, uri,
                    array.getJSONObject(i));
        }/*from w w  w .  ja va 2s.c o  m*/
    }

    public static void insertJSONObjectContent(
            ContentResolver contentResolver, Uri uri, JSONObject obj)
            throws JSONException {
        ContentValues values = new ContentValues();
        Iterator<String> it = (Iterator<String>) obj.keys();
        while (it.hasNext()) {
            String key = it.next();
            values.put(key, obj.getString(key));
        }
        contentResolver.insert(uri, values);
    }
}

Related

  1. insertJSONObjectContent( ContentResolver contentResolver, Uri uri, JSONObject obj)
  2. concatArray(JSONArray arr1, JSONArray arr2)