Skip to Content
Java クックブック、第 4 版
book

Java クックブック、第 4 版

by Ian F. Darwin
May 2025
Intermediate to advanced
638 pages
10h 22m
Japanese
O'Reilly Media, Inc.
Content preview from Java クックブック、第 4 版

第14章. JSONデータを処理する

この作品はAIを使って翻訳されている。ご意見、ご感想をお待ちしている:translation-feedback@oreilly.com

14.0 はじめに

JSON(JavaScriptオブジェクト記法)とは、以下のすべてを指す:

  • シンプルで軽量なデータ交換形式。

  • XMLに代わる、よりシンプルで軽量なものである。

  • println() またはいくつかのAPIを使って簡単に生成できる。

  • すべてのウェブブラウザのJavaScriptパーサーによって直接認識される。

  • すべての一般的な言語(Java、C/C++、Perl、Ruby、Python、Lua、Erlang、Haskellなど)のアドオン・フレームワークをサポートしており、サポートされている言語のとんでもなく長いリスト(Java用だけで2ダースのパーサーを含む)がホームページ上にある。

単純なJSONメッセージは次のようになる:

json/src/main/resources/json/softwareinfo.json/を参照のこと。

{
  "name": "robinparse",
  "version": "1.2.3",
  "description": "Another Parser for JSON",
  "className": "RobinParse",
  "contributors": [
        "Robin Smythe",
        "Jon Jenz",
        "Jan Ardann"
    ]
}

見ての通り、構文はシンプルで、入れ子にすることができ、人間による検査も可能である。

JSONのホームページでは、JSONの構文を簡潔にまとめている。 構造には2種類ある:JSONオブジェクト(マッピング)とJSON配列(リスト)である。JSONオブジェクトは、名前と値のペアのセットであり、java.util.Map 、またはJavaオブジェクトのプロパティとして表現できる。たとえば、2019年4月1日のLocalDateレシピ6.1参照)オブジェクトのフィールドは、次のように表現できる:

{
	"year": 2019,
	"month": 4,
	"day" : 1
}

JSON配列は、順序付けられたリストであり、Javaでは配列またはjava.util.Listsとして表現される。2つの日付のリストは次のようになる:

{
	[{
		"year": 2019,
		"month": 4,
		"day" : 1
	},{
		"year": 2019,
		"month": 5,
		"day" : 15
	}]
}

JSONは自由形式であるため、人間の読みやすさは多少損なわれるものの、情報や関数を損なうことなく、このように書くこともできる:

{[{"year":2019,"month":4,"day":1},{"year":2019,"month":5,"day":15}]}

JSONのために書かれたパーサーは、何百とあるだろう。Javaの世界で思い浮かぶものには、以下のようなものがある:

stringtree.org

非常に小型・軽量

json.org parser

無料であり、良いドメイン名を持っているため、広く利用されている。

jackson.org parser

SpringフレームワークやJBoss RESTEasy、Wildflyと共に使用され、非常に強力であるため、広く使用されている。

javax.json

オラクルの公式規格だが、現在はEE専用となっている。 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

最新の Java レシピ

最新の Java レシピ

Ken Kousen
Javaによる関数型プログラミング ―Java 8ラムダ式とStream

Javaによる関数型プログラミング ―Java 8ラムダ式とStream

Venkat Subramaniam, 株式会社プログラミングシステム社
MySQL クックブック、第 4 版

MySQL クックブック、第 4 版

Sveta Smirnova, Alkin Tezuysal

Publisher Resources

ISBN: 9798341650336