2

I am storing an image in form of String using Base64 encoding. I wish to send that image to API and get jSON object response. I have deployed the same in Android using ArrayList, but Since iOS does not have ArrayList. How can this be done.

ArrayList nameValuePairs = new ArrayList();

  nameValuePairs.add(new BasicNameValuePair("serialnumber",ReplaceString(UserData.objUserData.getencryptedTerminalid()).trim()));
  nameValuePairs.add(new BasicNameValuePair("mobileimei",ReplaceString(EncryptionHelper.encryptText(telephonyManager.getDeviceId())).trim()));
  nameValuePairs.add(new BasicNameValuePair("submerchantguid",ReplaceString(EncryptionHelper.encryptText(Payment.merchantId)).trim()));
  nameValuePairs.add(new BasicNameValuePair("transactionid",ReplaceString(EncryptionHelper.encryptText(Payment.transactionId))));
  nameValuePairs.add(new BasicNameValuePair("emailid",ReplaceString(EncryptionHelper.encryptText(userEmail)).trim()));
  nameValuePairs.add(new BasicNameValuePair("mobileno",ReplaceString(EncryptionHelper.encryptText(userMobile)).trim()));
  nameValuePairs.add(new BasicNameValuePair("signature",encodedSignImage));
  nameValuePairs.add(new BasicNameValuePair("photo",encodedPhotoImage.trim()));


  InputStream is;
  // open data output stream
  OutputStream dos;

  HttpClient httpclient = new DefaultHttpClient();

  HttpPost httppost = new

  HttpPost(Constants.INFO_SUBMIT);

  httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

  HttpResponse response = httpclient.execute(httppost);

  HttpEntity entity = response.getEntity();

  is = entity.getContent();

  int ch;
  StringBuffer b = new StringBuffer();
  String responseString = "";

  while ((ch = is.read()) != -1) 
  {
   b.append((char) ch);
  }

  responseString = b.toString();
  JSONObject jsonObject = new JSONObject(responseString);
  statusString = (String) jsonObject.get("Status");

    }
 }
CodaFi
  • 43,043
  • 8
  • 107
  • 153
onkar
  • 29
  • 5

1 Answers1

0

There are really three separate questions here, which I'll answer individually:

  1. In terms of communicating with a web service, you should check out RestKit or ASIHTTPRequest or AFNetworking or something like that. If you're interested in writing your own, you'd use NSURLConnection which you can see discussed in the URL Loading System Programming Guide. You can also look at the various examples you'll see in the NSURLConnection Class Reference, such as SimpleURLConnections

  2. In terms of parsing/creating JSON, you can use NSJSONSerialization.

  3. In terms of base64 coding, I've successfully used Google GTMBase64 in GTM. But I'd suggest you look at How do I do base64 encoding on iphone-sdk?

Community
  • 1
  • 1
Rob
  • 415,655
  • 72
  • 787
  • 1,044