//200-299 > Success 400 -499 > Error 500 - 599 > Server error
// System.out.println(httpURLConnection.getResponseCode());
BufferedReader bufferedReader =
new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
StringBuilder stringBuilder = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
stringBuilder.append(line);
}
bufferedReader.close();
Type type = new TypeToken>() {
}.getType();
Gson gson = new Gson();
ArrayList list = gson.fromJson(stringBuilder.toString(), type);
for (Money money : list) {
System.out.println("1 " + money.getCcyNmUZ() + " > " + money.getRate()+" so`m");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Money classida ma`lumotlar joylashadi:
package money;
import com.google.gson.annotations.SerializedName;
public class Money{
@SerializedName("CcyNm_EN")
private String ccyNmEN;
@SerializedName("CcyNm_UZC")
private String ccyNmUZC;
@SerializedName("Diff")
private String diff;
@SerializedName("Rate")
private String rate;
@SerializedName("Ccy")
private String ccy;
@SerializedName("CcyNm_RU")
private String ccyNmRU;
@SerializedName("id")
private int id;
@SerializedName("CcyNm_UZ")
private String ccyNmUZ;
@SerializedName("Code")
private String code;
@SerializedName("Nominal")
private String nominal;
@SerializedName("Date")
private String date;
public String getCcyNmEN(){
return ccyNmEN;
}
public String getCcyNmUZC(){
return ccyNmUZC;
}
public String getDiff(){
return diff;
}
public String getRate(){
return rate;
}
public String getCcy(){
return ccy;
}
public String getCcyNmRU(){
return ccyNmRU;
}
public int getId(){
return id;
}
public String getCcyNmUZ(){
return ccyNmUZ;
}
public String getCode(){
return code;
}
public String getNominal(){
return nominal;
}
public String getDate(){
return date;
}
}
Dastur natijasi:
"D:\Program Files\jdk-14.0.2_windows-x64_bin\jdk-14.0.2\bin\java.exe" "-javaagent:D:\Program Files\IntelliJ IDEA Community Edition 2020.2.1\lib\idea_rt.jar=59504:D:\Program Files\IntelliJ IDEA Community Edition 2020.2.1\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\User\IdeaProjects\myfirstprogram\out\production\myfirstprogram;D:\programs\gson-2.2.2.jar money.Main
1 AQSH dollari > 10414.86 so`m
1 EVRO > 12344.73 so`m
1 Rossiya rubli > 136.69 so`m
1 Angliya funt sterlingi > 13833.02 so`m
1 Yaponiya iyenasi > 100.29 so`m
1 Ozarbayjon manati > 6151.72 so`m
1 Bangladesh takasi > 124.13 so`m
1 Bolgariya levi > 6313.95 so`m
1 Bahrayn dinori > 27654.97 so`m
1 Bruney dollari > 7754.34 so`m
1 Braziliya reali > 1935.96 so`m
1 Belorus rubli > 4082.66 so`m
1 Kanada dollari > 7952.70 so`m
1 Shveytsariya franki > 11433.59 so`m
1 Xitoy yuani > 1587.44 so`m
1 Kuba pesosi > 10414.86 so`m
1 Chexiya kronasi > 468.93 so`m
1 Daniya kronasi > 1658.26 so`m
1 Jazoir dinori > 81.11 so`m
1 Misr funti > 669.77 so`m
1 Afg‘oniston afg‘onisi > 135.45 so`m
1 Argentina pesosi > 129.62 so`m
1 Gruziya larisi > 3158.60 so`m
1 Vengriya forinti > 34.31 so`m
1 Indoneziya rupiyasi > 0.74 so`m
1 Isroil shekeli > 3118.50 so`m
1 Hindiston rupiyasi > 140.53 so`m
1 Iroq dinori > 8.77 so`m
1 Eron riali > 0.25 so`m
1 Islandiya kronasi > 76.73 so`m
1 Iordaniya dinori > 14710.25 so`m
1 Avstraliya dollari > 7604.93 so`m
1 Qirg‘iz somi > 122.82 so`m
1 Kambodja riyeli > 2.58 so`m
1 Koreya Respublikasi voni > 9.34 so`m
1 Quvayt dinori > 34091.19 so`m
1 Qozog‘iston tengesi > 24.35 so`m
1 Laos kipisi > 1.12 so`m
1 Livan funti > 6.92 so`m
1 Liviya dinori > 7701.02 so`m
1 Marokash dirhami > 1143.26 so`m
1 Moldaviya leyi > 610.28 so`m
1 Myanma kyati > 7.99 so`m
1 Mongoliya tugriki > 3.72 so`m
1 Meksika pesosi > 518.22 so`m
1 Malayziya ringgiti > 2546.42 so`m
1 Norvegiya kronasi > 1155.82 so`m
1 Yangi Zelandiya dollari > 7214.37 so`m
1 Ummon riali > 27072.68 so`m
1 Filippin pesosi > 215.94 so`m
1 Pokiston rupiyasi > 64.87 so`m
1 Polsha zlotiysi > 2765.57 so`m
1 Qatar riali > 2860.05 so`m
1 Ruminiya leyi > 2538.04 so`m
1 Serbiya dinori > 105.14 so`m
1 Armaniston drami > 20.98 so`m
1 Saudiya Arabistoni riali > 2777.30 so`m
1 Sudan funti > 189.36 so`m
1 Shvetsiya kronasi > 1208.42 so`m
1 Singapur dollari > 7754.34 so`m
1 Suriya funti > 8.29 so`m
1 Tailand bati > 343.84 so`m
1 Tojikiston somonisi > 919.63 so`m
1 Turkmaniston manati > 2984.20 so`m
1 Tunis dinori > 3797.30 so`m
1 Turkiya lirasi > 1364.58 so`m
1 Ukraina grivnasi > 367.89 so`m
1 BAA dirhami > 2835.67 so`m
1 Urugvay pesosi > 243.28 so`m
1 Venesuela bolivari > 0.01 so`m
1 Vetnam dongi > 0.45 so`m
1 SDR > 14846.60 so`m
1 Yaman riali > 42.13 so`m
1 Janubiy Afrika randi > 675.80 so`m
Process finished with exit code 0
Markaziy bank saytida berilgan valyuta kurslar
Ko`rib turganimizdek biz tuzgan dastur natijasi bilan saytning o`zida berilgan valyuta kurslari bir xil.
Xulosa
Dastur bilan server o`rtasidagi aloqani ta`minlab beradi, va buni imkoniyatlari juda keng.
Foydalanilgan adabiyotlar:
https://en.wikipedia.org/wiki/API
https://scalac.io/rest-assured-api-testing-tutorial-java-scala/
https://docs.marklogic.com/guide/java/intro
Do'stlaringiz bilan baham: |