Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- Reflect
- Chrono
- go
- Functional
- Android
- stringprintf
- SHA512
- coroutines
- CustomTab
- program
- design pattern
- SHA1
- haskell
- sha256
- AES
- ranges
- kotlin
- c++
- sprintf
- traits
- Clojure
- web
- RAII
- type_traits
- async
- WebView
- template
- Scala
- Observer
- ChromeTab
Archives
- Today
- Total
프로그래밍 검색 블로그
안드로이드 REST API / JSON 파싱 본문
비트코인 API를 봐서...
Bittrex 에서 해외 비트코인 주소를 따와서 작성
저기 coinName에는 생성자로 받는다 (BTC) 등
1 | private val mRequestAddress = "https://bittrex.com/api/v1.1/public/getticker?market=USDT-$coinName" | cs |
저 주소로 요청하면 JSON의
{"success":true,"message":"","result":{"Bid":0.65900000,"Ask":0.65993000,"Last":0.65993000}}
값이 나온다
적당히 파싱을 하면
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | fun onRequestCoinPrice(): Double { val url = URL(mRequestAddress) val conn = url.openConnection() as HttpURLConnection BufferedReader(InputStreamReader (conn.inputStream, Charset.forName("UTF-8"))).use { reader -> // Bid : 살 때, // Ask : 팔 때, // Last : 최근 거래 가격 // {"success":true,"message":"","result":{"Bid":0.65900000,"Ask":0.65993000,"Last":0.65993000}} val response = reader.readLine() val json = JSONObject(response) val exchangePrice = (json["result"] as JSONObject).get("Last") return exchangePrice as Double } } | cs |
'Android' 카테고리의 다른 글
안드로이드 WebView 대신 Chrome Tab 사용 (1) | 2019.03.23 |
---|---|
코틀린 파일 MD5 SHA1 SHA256 SHA512 (0) | 2018.05.30 |
코틀린 비동기 async (0) | 2018.02.16 |
안드로이드 SQLite 사용 Create, Index (0) | 2018.02.12 |
안드로이드 웹뷰 성능 향상 (0) | 2017.12.30 |
Comments