Отправка сложного объекта JSON

Я хочу общаться с веб-сервером и обмениваться информацией JSON.

URL моего веб-сервиса выглядит следующим образом:http://46.157.263.140/EngineTestingWCF/DPMobileBookingService.svc/SearchOnlyCus

Вот мой формат запроса JSON.

{
    "f": {
        "Adults": 1,
        "CabinClass": 0,
        "ChildAge": [
            7
        ],
        "Children": 1,
        "CustomerId": 0,
        "CustomerType": 0,
        "CustomerUserId": 81,
        "DepartureDate": "/Date(1358965800000+0530)/",
        "DepartureDateGap": 0,
        "Infants": 1,
        "IsPackageUpsell": false,
        "JourneyType": 2,
        "PreferredCurrency": "INR",
        "ReturnDate": "/Date(1359138600000+0530)/",
        "ReturnDateGap": 0,
        "SearchOption": 1
    },
    "fsc": "0"
}

Я попытался с помощью следующего кода отправить запрос:

public class Fdetails {
    private String Adults = "1";
    private String CabinClass = "0";
    private String[] ChildAge = { "7" };
    private String Children = "1";
    private String CustomerId = "0";
    private String CustomerType = "0";
    private String CustomerUserId = "0";
    private Date DepartureDate = new Date();
    private String DepartureDateGap = "0";
    private String Infants = "1";
    private String IsPackageUpsell = "false";
    private String JourneyType = "1";
    private String PreferredCurrency = "MYR";
    private String ReturnDate = "";
    private String ReturnDateGap = "0";
    private String SearchOption = "1";
}

public class Fpack {
    private Fdetails f = new Fdetails();
    private String fsc = "0";
}

Затем с помощью Gson я создаюОбъект JSON лайк:

public static String getJSONString(String url) {
String jsonResponse = null;
String jsonReq = null;
Fpack fReq = new Fpack();

try {                                                
    Gson gson = new Gson();
    jsonReq = gson.toJson(fReq);                        
    JSONObject json = new JSONObject(jsonReq);
    JSONObject jsonObjRecv = HttpClient.SendHttpPost(url, json);
    jsonResponse = jsonObjRecv.toString();
} 
catch (JSONException e) {
                           e.printStackTrace();
                }               
return jsonResponse;
    }

и мойHttpClient.SendHttpPost метод

public static JSONObject SendHttpPost(String URL, JSONObject json) {

        try {
            DefaultHttpClient httpclient = new DefaultHttpClient();
            HttpPost httpPostRequest = new HttpPost(URL);

            StringEntity se;
            se = new StringEntity(json.toString());
            httpPostRequest.setEntity(se);
            se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));          
            HttpResponse response = (HttpResponse) httpclient.execute(httpPostRequest);
            HttpEntity entity = response.getEntity();
            if (entity != null) {
                // Read the content stream
                InputStream instream = entity.getContent();
                Header contentEncoding = response.getFirstHeader("Content-Encoding");
                if (contentEncoding != null && contentEncoding.getValue().equalsIgnoreCase("gzip")) {
                    instream = new GZIPInputStream(instream);
                }

                // convert content stream to a String
                String resultString= convertStreamToString(instream);
                instream.close();
                resultString = resultString.substring(1,resultString.length()-1); // remove wrapping "[" and "]"

                // Transform the String into a JSONObject
                JSONObject jsonObjRecv = new JSONObject(resultString);
            return jsonObjRecv;
            } 
    catch (Exception e)
        {
            e.printStackTrace();
        }
        return null;
    }

Теперь я получаю следующее исключение:

org.json.JSONException: Value !DOCTYPE of type java.lang.String cannot be converted to JSONObject
at org.json.JSON.typeMismatch(JSON.java:111)
at org.json.JSONObject.(JSONObject.java:158)
at org.json.JSONObject.(JSONObject.java:171)

и распечатка строки JSON непосредственно перед выполнением запроса выглядит следующим образом:

{
    "f": {
        "PreferredCurrency": "MYR",
        "ReturnDate": "",            
        "ChildAge": [
            7
        ],
        "DepartureDate": "Mar 2, 2013 1:17:06 PM",
        "CustomerUserId": 0,
        "CustomerType": 0,
        "CustomerId": 0,
        "Children": 1,
        "DepartureDateGap": 0,
        "Infants": 1,
        "IsPackageUpsell": false,
        "JourneyType": 1,
        "CabinClass": 0,
        "Adults": 1,
        "ReturnDateGap": 0,
        "SearchOption": 1

    },
    "fsc": "0"
}

Как мне решить это исключение? Заранее спасибо!

Ответы на вопрос(4)

Ваш ответ на вопрос