Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.97 KB | None | 0 0
  1. package com.vetdevelopers.vetnetwork;
  2.  
  3. import android.os.Bundle;
  4.  
  5. import org.json.JSONArray;
  6. import org.json.JSONException;
  7. import org.json.JSONObject;
  8.  
  9. import java.util.ArrayList;
  10. import java.util.Set;
  11.  
  12. public class BundleFunctions
  13. {
  14.  
  15. public JSONObject MakeJsonObjectFromBundle(Bundle bundle)
  16. {
  17. JSONObject json = new JSONObject();
  18. Set<String> keys = bundle.keySet();
  19. for (String key : keys)
  20. {
  21. try
  22. {
  23. // json.put(key, bundle.get(key)); see edit below
  24. json.put(key, JSONObject.wrap(bundle.get(key)));
  25. }
  26. catch (JSONException e)
  27. {
  28. //Handle exception here
  29. }
  30. }
  31. return json;
  32. }
  33.  
  34.  
  35. public Bundle MakeBundleFromJSON(String response)
  36. {
  37. Bundle bundle = new Bundle();
  38. try
  39. {
  40. JSONArray jsonArray = new JSONArray(response);
  41. JSONObject jsonObject = jsonArray.getJSONObject(0);
  42.  
  43. bundle.putString("Name", jsonObject.getString("name"));
  44. bundle.putString("ID", jsonObject.getString("id"));
  45. bundle.putString("Email", jsonObject.getString("email"));
  46. bundle.putString("Phone", jsonObject.getString("phone"));
  47. bundle.putString("BVC_Number", jsonObject.getString("bvc_reg"));
  48. bundle.putString("Password", jsonObject.getString("password"));
  49. bundle.putString("University", jsonObject.getString("university"));
  50. bundle.putString("Designation", jsonObject.getString("designation"));
  51. bundle.putString("Posting_Area", jsonObject.getString("posting_area"));
  52. bundle.putString("District", jsonObject.getString("district"));
  53. bundle.putString("Division", jsonObject.getString("division"));
  54. bundle.putString("BVA_Member", jsonObject.getString("bva_member"));
  55. bundle.putString("BVA_Number", jsonObject.getString("bva_number"));
  56. bundle.putString("BVA_Designation", jsonObject.getString("bva_designation"));
  57. bundle.putString("Email_Confirm", jsonObject.getString("email_confirm"));
  58. bundle.putString("Rand_Code", jsonObject.getString("rand_code"));
  59. bundle.putString("User_Request", jsonObject.getString("user_request"));
  60. bundle.putString("User_Type", jsonObject.getString("user_type"));
  61. bundle.putString("Admin_Email", jsonObject.getString("admin_email"));
  62. }
  63. catch (Exception exception)
  64. {
  65. exception.printStackTrace();
  66. System.out.println("-----------BundleFunctions : --------string response error occured ------------!!!");
  67.  
  68. }
  69. return bundle;
  70. }
  71.  
  72. public ArrayList<String> MakeArrayListFormJSON(String response)
  73. {
  74. ArrayList<String> al = new ArrayList<String>();
  75. try
  76. {
  77. JSONArray jsonArray = new JSONArray(response);
  78. JSONObject jsonObject = jsonArray.getJSONObject(0);
  79.  
  80. al.add(jsonObject.getString("name"));
  81. al.add(jsonObject.getString("id"));
  82. al.add(jsonObject.getString("email"));
  83. al.add(jsonObject.getString("phone"));
  84. al.add(jsonObject.getString("bvc_reg"));
  85. al.add(jsonObject.getString("password"));
  86. al.add(jsonObject.getString("university"));
  87. al.add(jsonObject.getString("designation"));
  88. al.add(jsonObject.getString("posting_area"));
  89. al.add(jsonObject.getString("district"));
  90. al.add(jsonObject.getString("division"));
  91. al.add(jsonObject.getString("bva_member"));
  92. al.add(jsonObject.getString("bva_number"));
  93. al.add(jsonObject.getString("bva_designation"));
  94. al.add(jsonObject.getString("email_confirm"));
  95. al.add(jsonObject.getString("rand_code"));
  96. al.add(jsonObject.getString("user_request"));
  97. al.add(jsonObject.getString("user_type"));
  98. al.add(jsonObject.getString("admin_email"));
  99. }
  100. catch (Exception exception)
  101. {
  102. exception.printStackTrace();
  103. }
  104. return al;
  105. }
  106.  
  107. public ArrayList<String> MakeArrayListWithNewLineFormJSON(String response)
  108. {
  109. ArrayList<String> al = new ArrayList<String>();
  110. try
  111. {
  112. JSONArray jsonArray = new JSONArray(response);
  113. JSONObject jsonObject = jsonArray.getJSONObject(0);
  114.  
  115. al.add(jsonObject.getString("name" + "\n"));
  116. al.add(jsonObject.getString("id" + "\n"));
  117. al.add(jsonObject.getString("email" + "\n"));
  118. al.add(jsonObject.getString("phone" + "\n"));
  119. al.add(jsonObject.getString("bvc_reg" + "\n"));
  120. al.add(jsonObject.getString("password" + "\n"));
  121. al.add(jsonObject.getString("university" + "\n"));
  122. al.add(jsonObject.getString("designation" + "\n"));
  123. al.add(jsonObject.getString("posting_area" + "\n"));
  124. al.add(jsonObject.getString("district" + "\n"));
  125. al.add(jsonObject.getString("division" + "\n"));
  126. al.add(jsonObject.getString("bva_member" + "\n"));
  127. al.add(jsonObject.getString("bva_number" + "\n"));
  128. al.add(jsonObject.getString("bva_designation" + "\n"));
  129. al.add(jsonObject.getString("email_confirm" + "\n"));
  130. al.add(jsonObject.getString("rand_code" + "\n"));
  131. al.add(jsonObject.getString("user_request" + "\n"));
  132. al.add(jsonObject.getString("rand_code" + "\n"));
  133. al.add(jsonObject.getString("user_request" + "\n"));
  134. al.add(jsonObject.getString("user_type" + "\n"));
  135. al.add(jsonObject.getString("admin_email" + "\n"));
  136. }
  137. catch (Exception exception)
  138. {
  139. exception.printStackTrace();
  140. }
  141. return al;
  142. }
  143. public void setSharedPreference()
  144. {
  145.  
  146. }
  147.  
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement