Toshkent axborot texnologiyalari universiteti al-xorazmi nomidagt texnologiyalari universite


Download 35.82 Kb.
bet2/2
Sana16.11.2023
Hajmi35.82 Kb.
#1782109
1   2
Dastur kodi:
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
public class UrlConnecting {
public static void main(String[] args) {

try {
URL url = new URL("https://randomuser.me/api/");


URLConnection connection = url.openConnection();

InputStream stream = connection.getInputStream();

ByteArrayOutputStream baos = new ByteArrayOutputStream();

int len = stream.available();


byte[] data = new byte[len];
int n;

while ((n = stream.read(data)) > 0) {


baos.write(data, 0, n);
}

String content = new String(baos.toByteArray(), "UTF-8");


System.out.println(content);
} catch (Exception e) {
e.printStackTrace();
}

}
}
https://randomuser.me/api saytidan olingan json malumotlar:


https://randomuser.me/api bu sayt random qilib shaxsiy malumoti ochiq insonlar malumotini beradi json farmatda
Masalan: gender":
"female",
"name": {
"title": "Ms",
"first": "Ester",
"last": "Benner"
},
"location": {
"street": {
"number": 7129,



Json farmatdagi malumot:
{"results":[{"gender":"female","name":{"title":"Ms","first":"Ester","last":"Benner"},"location":{"street":{"number":7129,"name":"Danziger Straße"},"city":"Königs Wusterhausen","state":"Baden-Württemberg","country":"Germany","postcode":75236,"coordinates":{"latitude":"-52.6508","longitude":"176.4934"},"timezone":{"offset":"+5:00","description":"Ekaterinburg, Islamabad, Karachi, Tashkent"}},"email":"ester.benner@example.com","login":{"uuid":"40fab370-b499-4c65-b182-18ee740f9354","username":"bigbird569","password":"kestrel","salt":"rLLVzu7h","md5":"f4afe0eac3aea5ef32387a6df158a173","sha1":"42a48ca2acc7cae0c43f2c2bbb70a83aa8024aaa","sha256":"f32fd7ac82ada67868c5bacfded11eb986343a97f3fcbf9d8c71871a919ba517"},"dob":{"date":"1997-02-17T13:30:19.279Z","age":26},"registered":{"date":"2020-01-10T17:14:39.246Z","age":3},"phone":"0209-6232624","cell":"0178-1281634","id":{"name":"SVNR","value":"67 170297 B 537"},"picture":{"large":"https://randomuser.me/api/portraits/women/47.jpg","medium":"https://randomuser.me/api/portraits/med/women/47.jpg","thumbnail":"https://randomuser.me/api/portraits/thumb/women/47.jpg"},"nat":"DE"}],"info":{"seed":"f0bf9d3cbf1933cf","results":1,"page":1,"version":"1.4"}}
Markaziy bank saytidan 01.01.2005 yidagi EUR narxini aniqlash dasturli json famatda:



Json malumot:
[
{
"id": 1,
"Code": "978",
"Ccy": "EUR",
"CcyNm_RU": "Евро",
"CcyNm_UZ": "EVRO",
"CcyNm_UZC": "EВРО",
"CcyNm_EN": "Euro",
"Nominal": "1",
"Rate": "12897.60",
"Diff": "-3.9",
"Date": "20.10.2023"
}
]
EUR narxi Rate: 12897.60 so’m bo’lgan ekan.





Download 35.82 Kb.

Do'stlaringiz bilan baham:
1   2




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling