JavaでJsonPointerインターフェースを使用してキーの値を取得するにはどうすればよいですか?
import javax.json.*;
import java.io.*;
public class JsonPointerTest {
public static void main(String[] args) throws Exception {
JsonReader jsonReader = Json.createReader(new FileReader("simple.json"));
JsonStructure jsonStructure = jsonReader.read();
JsonPointer jsonPointer1 = Json.createPointer("/firstName");
JsonString jsonString = (JsonString)jsonPointer1.getValue(jsonStructure);
System.out.println("First Name: " + jsonString.getString()); // prints first name
JsonPointer jsonPointer2 = Json.createPointer("/phoneNumbers");
JsonArray array = (JsonArray)jsonPointer2.getValue(jsonStructure);
System.out.println("Phone Numbers:");
for(JsonValue value : array) {
JsonObject objValue = (JsonObject)value;
System.out.println(objValue.toString()); // prints phone numbers
}
JsonPointer jsonPointer3 = Json.createPointer("/phoneNumbers/1");
JsonObject jsonObject1 = (JsonObject)jsonPointer3.getValue(jsonStructure);
System.out.println("Home: " + jsonObject1.toString()); // prints home phone number
JsonPointer jsonPointer4 = Json.createPointer("");
JsonObject jsonObject2 = (JsonObject)jsonPointer4.getValue(jsonStructure);
System.out.println("JSON:\n" + jsonObject2.toString()); // prints JSON structure
jsonReader.close();
}
} First Name: Raja
Phone Numbers:
{"Mobile":"9959984000"}
{"Home":"0403758000"}
Home: {"Home":"0403758000"}
JSON:
{"firstName":"Raja","lastName":"Ramesh","age":30,"streetAddress":"Madhapur","city":"Hyderabad","state":"Telangana","phoneNumbers":[{"Mobile":"9959984000"},{"Home":"0403758000"}]} -
OpenCV Javaライブラリを使用して画像の要点を検出する方法は?
detect() org.opencv.features2d.Feature2Dのメソッド (抽象)クラスは、指定された画像の要点を検出します。この方法では、マットを渡す必要があります ソース画像を表すオブジェクトと空のMatOfKeyPoint 読み取りキーポイントを保持するオブジェクト。 drawKeypoints()を使用して、画像に描画キーポイントを描画できます。 org.opencv.features2d.Features2dのメソッド クラス。 注 Feature2Dは抽象クラスであるため、そのサブクラスの1つをインスタンス化してdetect()メソッドを呼び出す必要
-
JavaのGsonライブラリを使用してJSON文字列をファイルに書き込む方法は?
Gsonは、JavaオブジェクトをJSON表現に変換するために使用できるライブラリです。 。使用する主なクラスはGson new Gson()を呼び出すことで作成できます およびGsonBuilder クラスを使用してGsonインスタンスを作成できます。 JSON文字列をファイルに書き込む toJson()を使用する Gsonの方法 以下の例のクラス 例 import java.io.*; import com.google.gson.*; public class JSONToFileTest { public static void main(String[