Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. package com.example.magdalena.lokalizacja;
  2.  
  3. import android.util.Log;
  4.  
  5. import org.json.JSONArray;
  6. import org.json.JSONException;
  7. import org.json.JSONObject;
  8.  
  9. /**
  10. * Created by Magdalena on 2016-11-30.
  11. */
  12.  
  13. public class BudowanieJSON {
  14. private static JSONArray lokalizacjaJsonArray = new JSONArray();
  15. private static JSONArray watmoJsonArray = new JSONArray();
  16. private static JSONArray dzwiekJsonArray = new JSONArray();
  17. private static JSONArray swiatloJsonArray = new JSONArray();
  18.  
  19. public static JSONObject jsonToSend = new JSONObject();
  20.  
  21. public static void lokalizacjaJSONArray(double lat, double lon) {
  22.  
  23.  
  24. Log.i("TAG", "activityJSONArray");
  25. JSONObject jsonObject = new JSONObject();
  26. try {
  27. jsonObject.put("lat", lat);
  28. jsonObject.put("lon", lon);
  29.  
  30. Log.i("TAG", "json: " + jsonObject.toString());
  31.  
  32. } catch (JSONException je) {
  33. je.printStackTrace();
  34. } catch (Exception e) {
  35. e.printStackTrace();
  36. }
  37. lokalizacjaJsonArray.put(jsonObject);
  38. Log.i("TAG", "json: " + lokalizacjaJsonArray.toString());
  39.  
  40. }
  41.  
  42. public static void watmoJSONArray(String miasto, String temperatura, String cisnienie) {
  43.  
  44.  
  45. Log.i("TAG", "activityJSONArray");
  46. JSONObject jsonObject = new JSONObject();
  47. try {
  48. jsonObject.put("miasto", miasto);
  49. jsonObject.put("temperatura", temperatura);
  50. jsonObject.put("cisnienie", cisnienie);
  51.  
  52. Log.i("TAG", "json: " + jsonObject.toString());
  53.  
  54. } catch (JSONException je) {
  55. je.printStackTrace();
  56. } catch (Exception e) {
  57. e.printStackTrace();
  58. }
  59. watmoJsonArray.put(jsonObject);
  60. Log.i("TAG", "json: " + watmoJsonArray.toString());
  61.  
  62. }
  63.  
  64.  
  65. public static void dzwiekJsonArray(double db){
  66.  
  67. Log.i("TAG", "activityJSONArray");
  68. JSONObject jsonObject = new JSONObject();
  69. try{
  70. jsonObject.put("decybele", db);
  71. }catch (JSONException je){
  72. je.printStackTrace();
  73. }catch (Exception e){
  74. e.printStackTrace();
  75. }
  76. dzwiekJsonArray.put(jsonObject);
  77. Log.i("TAG", "json:" + dzwiekJsonArray.toString());
  78. }
  79.  
  80. public static void swiatloJSonArray(int lux){
  81.  
  82. Log.i("TAG", "activityJSONArray");
  83. JSONObject jsonObject = new JSONObject();
  84.  
  85. try {
  86. jsonObject.put("lux", lux);
  87.  
  88. }catch (JSONException je){
  89. je.printStackTrace();
  90.  
  91. }catch (JSONException e){
  92. e.printStackTrace();
  93. }
  94. swiatloJsonArray.put(jsonObject);
  95. Log.i("TAG", "json:" + swiatloJsonArray.toString());
  96. }
  97.  
  98.  
  99. public static JSONObject bulidJSONToSend() {
  100.  
  101. try {
  102. jsonToSend.put("lokalizacja", lokalizacjaJsonArray);
  103. jsonToSend.put("pogoda", watmoJsonArray);
  104. jsonToSend.put("decybele", dzwiekJsonArray);
  105. jsonToSend.put("lux", swiatloJsonArray);
  106.  
  107. } catch (JSONException je) {
  108. je.printStackTrace();
  109. } catch (Exception e) {
  110. e.printStackTrace();
  111. }
  112. return jsonToSend;
  113. }
  114.  
  115.  
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement