2014-11-10 2 views
-2

안녕하세요 Base64로 형식으로 JSONArray을 변환 서버
나는 내가 가진이
JSONArray를 Android64에서 Base64 형식으로 변환하는 방법은 무엇입니까?

JsonArray jArray = new JSONArray(<<ArrayList NAME>>); 


    [{previous_cost=No Previous Cost Available, id=B00PDBKATW, localCost=4.52, time=2014-12-10   17:22:08, totalCost=39.51, Price=$32.52, Shipping=$6.99, upc_code=603084267415, Product_name=(3 Piece Bundle) Garnier Fructis Sleek & Shine Shampoo Conditioner and Anti-Frizz Serum With Argan Oil from Morocco}, {previous_cost=$19.99, id=B0029PQ2MY, localCost=10, time=2014-12-10 17:59:21, totalCost=26.98, Price=$19.99, Shipping=$6.99, upc_code=041116006258, Product_name=24 each: Topps Ring Pop (625)}, {previous_cost=$64.98, id=B009S28ON6, localCost=10, time=2014-12-10 17:59:20, totalCost=71.13, Price=$64.98, Shipping=$6.15, upc_code=041116006258, Product_name=Bazooka Ring Pop Box 0.50 Ounce (Pack of 24)}, {previous_cost=No Previous Cost Available, id=B00CUGBH5Y, localCost=4.52, time=2014-12-10 17:22:09, totalCost=37.10, Price=$37.10, Shipping=No Shipping, upc_code=603084267415, Product_name=FRUCTIS SLEEKand SHINE COND 13OZ}, {previous_cost=No Previous Cost Available, id=B005GQ6F4I, localCost=4.52, time=2014-12-10 17:22:08, totalCost=9.83, Price=$4.58, Shipping=No Shipping, upc_code=603084267415, Product_name=Garnier Conditioner Sleek and Shine 13 Fluid Ounce}, {previous_cost=No Previous Cost Available, id=B00OJC2QCU, localCost=4.52, time=2014-12-10 17:22:09, totalCost=40.99, Price=$40.99, Shipping=No Shipping, upc_code=603084267415, Product_name=Garnier Conditioner Sleek and Shine 13 Fluid Ounce (4 Pack)}, {previous_cost=No Previous Cost Available, id=B00NFUJM1K, localCost=4.52, time=2014-12-10 17:22:08, totalCost=20.99, Price=$20.99, Shipping=No Shipping, upc_code=603084267415, Product_name=Garnier Fructis Conditioner Sleek & Shine 13oz Frizzy/Dry (2 Pack)}, {previous_cost=No Previous Cost Available, id=B00GMP7VZE, localCost=4.52, time=2014-12-10 17:22:09, totalCost=30.99, Price=$30.99, Shipping=No Shipping, upc_code=603084267415, Product_name=Garnier Fructis Conditioner Sleek & Shine 13oz Frizzy/Dry (3 Pack)}, {previous_cost=No Previous Cost Available, id=B00G4EPV78, localCost=4.52, time=2014-12-10 17:22:10, totalCost=61.99, Price=$61.99, Shipping=No Shipping, upc_code=603084267415, Product_name=Garnier Fructis Conditioner Sleek & Shine 13oz Frizzy/Dry (6 Pack)}, {previous_cost=$21.62, id=B00FFJ0AEM, localCost=12, time=2014-12-10 17:54:53, totalCost=27.61, Price=$21.62, Shipping=$5.99, upc_code=037000867616, Product_name=Old Spice Swagger Body Wash - Man Sized - Convenient Pump Bottle - 32 Fluid Ounces}, {previous_cost=No Previous Cost Available, id=B00EA8DU1O, localCost=12, time=2014-12-10 17:35:51, totalCost=0.00, Price=0,00, Shipping=No Shipping, upc_code=080878173228, Product_name=Pantene Pro-V Anti-Breakage Shampoo 22.8 Fluid Ounce}, {previous_cost=$19.99, id=B00D97KV14, localCost=10, time=2014-12-10 17:59:21, totalCost=25.98, Price=$19.99, Shipping=$5.99, upc_code=041116006258, Product_name=RING POP ORIG .5 OUNCES 24 COUNT}, {previous_cost=$19.95, id=B0052Y49PG, localCost=10, time=2014-12-10 17:59:20, totalCost=25.44, Price=$19.95, Shipping=$5.49, upc_code=041116006258, Product_name=Ring Pop Fruit Fest (24 pack)}, {previous_cost=No Previous Cost Available, id=B0087W58DW, localCost=10, time=2014-12-10 17:55:23, totalCost=47.78, Price=$47.78, Shipping=No Shipping, upc_code=074182290948, Product_name=Softsoap Elements Milk Protein & Honey Moisturizing Hand Soap 7.5 oz (Pack of 12)}, {previous_cost=No Previous Cost Available, id=B00CQ561EG, localCost=10, time=2014-12-10 17:55:24, totalCost=14.59, Price=$14.59, Shipping=No Shipping, upc_code=074182290948, Product_name=Softsoap Elements Milk Protein and Honey Moisturizing Hand Soap 7.5 oz (Pack of 2)}, {previous_cost=No Previous Cost Available, id=B00KOBQ78Y, localCost=10, time=2014-12-10 17:55:24, totalCost=200.24, Price=$200.24, Shipping=No Shipping, upc_code=074182290948, Product_name=Softsoap Moisturizing Hand Soap Milk & Golden Honey}] 

같은 JSON 배열에 인수로 ArrayList에를 부여하고 그것을에 게시 할 할 이 시도

String Encoded = new String(Base64.decode(jArray.toString(), Base64.DEFAULT)); 

및 서버에 jsonarray 게시에 대한 코드

,

DefaultHttpClient httpClient = new DefaultHttpClient(); 
     HttpPost httpPost = new HttpPost(<<URL WHERE DATA IS POSTING>>); 
     try{ 
      String Encoded = Base64.encodeToString((jArray.toString()).getBytes(), Base64.DEFAULT); 
      String param = Encoded; 
      sBuilder = new StringBuilder(); 
      List<NameValuePair> list = new ArrayList<NameValuePair>(); 
      list.add(new BasicNameValuePair("var1", param)); 
      Log.d("Params", ""+list); 
      Log.d("Encoded Format", ""+Encoded); 

      decoded = Base64.decode(param, Base64.DEFAULT); 
      Log.d("decoded byte Format", ""+Encoded); 
      Log.d("Decoded Format", ""+Decoded); 
      httpPost.setEntity(new UrlEncodedFormEntity(list)); 
      HttpResponse httpResponse = httpClient.execute(httpPost); 
      Log.d("HttpResponse", ""+httpResponse); 
      StatusLine statusLine = httpResponse.getStatusLine(); 
      int i = statusLine.getStatusCode(); 
      if(i == 200){ 

       BufferedReader reader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent())); 
       String data = reader.readLine(); 

       sBuilder.append(data); 

      } 
      Log.d("Getting JSON","JSON data DownLoad"+ "\n" + sBuilder); 
      isMailSent = true; 
     }catch(Exception e){ 


     } 

와 나는 같은 인코딩 된 문자열 로그를 가지고 결과로 : -

12-11 16:06:46.785: D/Encoded Format(6514): WyJ7cHJldmlvdXNfY29zdD1ObyBQcmV2aW91cyBDb3N0IEF2YWlsYWJsZSwgaWQ9QjAwUERCS0FU 
12-11 16:06:46.785: D/Encoded Format(6514): VywgbG9jYWxDb3N0PTQuNTIsIHRpbWU9MjAxNC0xMi0xMCAxNzoyMjowOCwgdG90YWxDb3N0PTM5 
12-11 16:06:46.785: D/Encoded Format(6514): LjUxLCBQcmljZT0kMzIuNTIsIFNoaXBwaW5nPSQ2Ljk5LCB1cGNfY29kZT02MDMwODQyNjc0MTUs 
12-11 16:06:46.785: D/Encoded Format(6514): IFByb2R1Y3RfbmFtZT0oMyBQaWVjZSBCdW5kbGUpIEdhcm5pZXIgRnJ1Y3RpcyBTbGVlayAmIFNo 

나는 하나의 문자열로 이러한 인코딩 된 문자열을 원하지만이 부분으로 인코딩합니다. 감사합니다.

답변

0

메서드 Base63.decode()은 즉, base64 -> JSONArray를 나타내는 문자열 역 변환을 원합니다. Base64.encode 방법을 대신 사용하십시오

+0

오! 내가 얼마나 바보인지. @nnesterov에게 감사합니다. –

+0

나는 Base64.encode 메서드를 사용했지만 전체 jsonArray를 인코딩하지 않는다고 생각합니다. 거기에 어떤 방법이나 jsonArray 인코딩 방법입니다. –

+0

json 배열 및 base64 결과에 질문을 추가하십시오. 또한 변환을 위해 사용하는 코드를 게시하십시오 – nnesterov

관련 문제