簡體   English   中英

我可以將JSON-LD轉換為Java對象嗎?

[英]Can I transform a JSON-LD to a Java object?

編輯 :我改變了主意。 我會找到一種方法來生成Java類並將JSON作為該類的對象加載。


我剛剛發現存在一個名為JSON-LDJSON變體。

在我看來,這是一種更有條理的定義JSON ,它提醒我XML與關聯的模式,如XSD

我可以從JSON-LD創建Java類,在運行時加載它並使用它將JSON-LD轉換為該類的實例化嗎?

我閱讀了兩個實現的文檔,但我一無所獲。 也許我讀得不好?

進行Google搜索將我帶到了一個庫,該庫將JSON-LD解碼為“未定義” Object

// Open a valid json(-ld) input file
InputStream inputStream = new FileInputStream("input.json");
// Read the file into an Object (The type of this object will be a List, Map, String, Boolean,
// Number or null depending on the root object in the file).
Object jsonObject = JsonUtils.fromInputStream(inputStream);
// Create a context JSON map containing prefixes and definitions
Map context = new HashMap();
// Customise context...
// Create an instance of JsonLdOptions with the standard JSON-LD options
JsonLdOptions options = new JsonLdOptions();
// Customise options...
// Call whichever JSONLD function you want! (e.g. compact)
Object compact = JsonLdProcessor.compact(jsonObject, context, options);
// Print out the result (or don't, it's your call!)
System.out.println(JsonUtils.toPrettyString(compact));

https://github.com/jsonld-java/jsonld-java

顯然,它也可以從一個字符串中獲取它,就像從文件或其他來源讀取它一樣。 你怎么訪問object的內容,我分不清楚。 但是,文檔看起來似乎還算適當。

它似乎是一個活躍的項目,因為最后一次提交僅在4天前,並有30個貢獻者。 許可證是BSD 3條款,如果這對您有任何影響。

我與這個項目無關。 我不是作者,也沒有提出拉動請求。 這只是我發現的東西。

祝你好運,我希望這有幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM