Java活用生活

ログイン

オンライン状況

オンラインユーザー1人
ログインユーザー0人
登録ユーザー2人

カウンタ

COUNTER335467

日誌

MyDoc(備忘録) >> 記事詳細
2023/01/05

Json基礎

固定リンク | by:aramaki
Json基礎
-------------
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

public class JsonReadToString {

public static void main(String[] args) throws Exception {
String json = "{"
+ "\"created_at\":\"Thu Apr 06 15:24:15 +0000 2017\", "
+ "\"id\": 850006245121695744, "
+ "\"text\": \"ツイート\""
+ "}";

ObjectMapper mapper = new ObjectMapper();
JsonNode node = mapper.readTree(json);

System.out.println(node.get("id").longValue()); // → 850006245121695744
System.out.println(node.get("text").textValue()); // → "ツイート"
System.out.println(node.get("created_at").textValue()); // → "Thu Apr 06 15:24:15 +0000 2017"
}

}
08:37 | 投票する | 投票数(0) | コメント(0)
Copyright © Java活用生活 All Rights Reserved .