从 Vertex 实例中获取 Json 格式的字符串

Obtain a String in Json format from a Vertex instance

在带有 OrientDB 数据库的 Java 应用程序中,在我拥有 Vertex 对象之后,我需要将其属性提取到 String 对象中。此对象必须采用 Json 格式。 预期结果的示例是:

 {"@type":"d","@rid":"#13:1093","@version":1,"@class":"V_Notification","lastUpdateDate":"2016-07-20 16:45:31","lastUpdateUser":"#12:41","creationDate":"2016-07-20 16:45:31","creationUser":"#12:41","type":"user_added_to_share_made_upload","description":"user_added_to_share_made_upload","sphereId":"#16:18","out_E_NotificationUser":["#45:1091"],"deleted":false,"version":0,"isRead":false,"@fieldTypes":"lastUpdateDate=t,lastUpdateUser=x,creationDate=t,creationUser=x,out_E_NotificationUser=g"}

您可以尝试 gson library 而不是使用类似的东西:

Gson gson = new Gson(); String jsonInString = gson.toJson(yourOrientObj);

参考:mkyong.com

我举了一个例子来验证你的情况:

@class: V_Notification

Property: 描述

Vertex v = graph.getVertex("#17:0");
Gson gson = new Gson();
String jsonInString = gson.toJson(v.getProperty("description").toString());
System.out.println("STAMPO = " + jsonInString);

这是我的输出:

PRINTED = "user_added_to_share_made_upload"

希望对您有所帮助。

此致。

你可以使用

OrientVertex v=g.getVertex("#9:0");
ODocument d=v.getRecord();
String json=d.toJSON();

希望对您有所帮助