/**
 * A HTTP plugin for Cordova / Phonegap
 */
package com.synconset;

import java.net.UnknownHostException;
import java.util.Map;

import org.apache.cordova.CallbackContext;
import org.json.JSONException;
import org.json.JSONObject;

import javax.net.ssl.SSLHandshakeException;

import android.util.Log;

import com.github.kevinsawicki.http.HttpRequest;
import com.github.kevinsawicki.http.HttpRequest.HttpRequestException;
 
public class CordovaHttpPostJson extends CordovaHttp implements Runnable {
    
    public CordovaHttpPostJson(String urlString, JSONObject jsonObj, Map<String, String> headers, CallbackContext callbackContext) {
        super(urlString, jsonObj, headers, callbackContext);
    }
    
    @Override
    public void run() {
        try {
            HttpRequest request = HttpRequest.post(this.getUrlString());
            this.setupSecurity(request);
            request.headers(this.getHeaders());
            request.acceptJson();
			request.form(getJsonObject().toString());
            int code = request.code();
            String body = request.body(CHARSET);
            JSONObject response = new JSONObject();
            response.put("status", code);
            if (code >= 200 && code < 300) {
                response.put("data", new JSONObject(body));
                this.getCallbackContext().success(response);
            } else {
                response.put("error", new JSONObject(body));
                this.getCallbackContext().error(response);
            }
        } catch (JSONException e) {
            this.respondWithError("There was an error generating the response");
        }  catch (HttpRequestException e) {
            if (e.getCause() instanceof UnknownHostException) {
                this.respondWithError(0, "The host could not be resolved");
            } else if (e.getCause() instanceof SSLHandshakeException) {
                this.respondWithError("SSL handshake failed");
            } else {
                this.respondWithError("There was an error with the request");
            }
        }
    }
}
@@ -124,16 +124,42 @@
 til.Map;
+%0Aimport java.util.HashMap;
 %0A%0Aimport
@@ -253,16 +253,75 @@
 NObject;
+%0Aimport org.json.JSONArray;%0A%0Aimport android.text.TextUtils;
 %0A%0Aimport
@@ -503,16 +503,44 @@
 ception;
+%0A%0Aimport java.util.Iterator;
 %0A %0Apubli
@@ -614,24 +614,61 @@
  %7B%0A    %0A    
+final String KEY_FORMAT = %22%5B%25s%5D%22;%0A%09%0A%09
 public Cordo
@@ -847,24 +847,1786 @@
 ext);%0A    %7D%0A
+%09%0A%09private Map%3CString, String%3E parseJson(JSONObject jsonObject, String prefix)%0A    %7B%0A        Map%3CString, String%3E entities = new HashMap();%0A%0A        if(jsonObject == null)%0A            return entities;%0A%0A        if(prefix == null)%0A            prefix = %22%22;%0A%0A        try%0A        %7B%0A            Iterator%3CString%3E iterator = jsonObject.keys();%0A            while (iterator.hasNext()) %7B%0A                String key = iterator.next();%0A                try %7B%0A                    Object value = jsonObject.get(key);%0A                    if(value == null)%0A                        continue;%0A%0A                    if ( value instanceof JSONObject ) %7B%0A                        entities.putAll(parseJson((JSONObject) value, prefix + key));%0A                    %7D%0A                    else if( value instanceof JSONArray)%7B%0A                        for (int i = 0; i %3C ((JSONArray) value).length(); i++) %7B%0A                            entities.putAll(parseJson(((JSONArray) value).getJSONObject(i),%0A                                            prefix +%0A                                            key +%0A                                            String.format(KEY_FORMAT, String.valueOf(i))));%0A                        %7D%0A                    %7D%0A                    else%0A                    %7B%0A                        if(!TextUtils.isEmpty(prefix)) //Don't add bracket to the root elements!%0A                            key = prefix + String.format(KEY_FORMAT, key);%0A%0A                        entities.put(key, String.valueOf(value));%0A                    %7D%0A                %7D catch (JSONException e) %7B%0A                    e.printStackTrace();%0A                %7D%0A            %7D%0A        %7D%0A        catch (Exception ex)%0A        %7B%0A            ex.printStackTrace();%0A        %7D%0A%0A        return entities;%0A    %7D%0A
     %0A    @Ov
@@ -2836,42 +2836,8 @@
 ));%0A
-            request.acceptJson();%0A
 %09%09%09r
@@ -2848,16 +2848,26 @@
 st.form(
+parseJson(
 getJsonO
@@ -2877,18 +2877,14 @@
 ct()
-.toString(
+, null
 ));%0A

Modify postJson method