들어가기 앞서
- dart를 통해 rpc2.0 통신으로 데이터를 읽어들일 수 있는지 확인하기 위함
- 결론 : 가능은 하지만 class를 만들어야 되는 귀차니즘이 발동하게 됨 ( 이 부분에 있어 좀 더 확인이 필요 )
개발
- 계정정보 확인용 (condenser_api.get_accounts) 메소드를 테스트 해보기로 함.
- http 패키지를 활용하여 json 정보를 encode 하여 post 처리
스크린샷
소스코드
import 'package:http/http.dart' as http;
import 'dart:convert';
main(List<String> args) {
requestMethod().then((val){
var sa = new SteemitAccounts.fromJson(json.decode(val.body));
// print(val.body);
print(sa.id);
print(sa.balance);
print(sa.name);
print(sa);
});
}
class SteemitAccounts {
dynamic result;
int id;
String balance;
String name;
SteemitAccounts.fromJson(Map<dynamic,dynamic> res) {
this.result = res['result'][0];
this.id = this.result['id'];
this.balance = this.result['balance'];
this.name = this.result['name'];
}
}
Future<http.Response> requestMethod() async {
var url = "https://api.steemit.com";
var body = json.encode({"jsonrpc":"2.0", "method":"condenser_api.get_accounts", "params":[["wonsama"]], "id":1});
return http.post(url, body: body);
}
결론
- 잘 됨
- 하지만 바인딩용 class를 만들어야 되는 귀차니즘이 존재. (물론 이 또한 타언어에서 코드를 생산해서 처리가 가능하긴하지만 ... 자바에서 vo를 매번 만드는 꼴과 유사해서 흠)
추가스샷 : json 문제점 ...
Sponsored ( Powered by dclick )
어떻게 스팀파워를 쓰면 좋을까요? 개인적생각 정리
스팀파워를 어떻게 쓰면 좋을지에 대한 개인적을 정리했습니다. 먼져 셀프보팅하면 욕을 먹는다. ...