javaxjson-toString仍然返回内存值

javaxjson-toString仍然返回内存值,java,json,java-7,tostring,Java,Json,Java 7,Tostring,我正在尝试将stanford nlp输出通过管道传输到json。我尝试使用简单的json,一切都很好。当我尝试使用javax.json时,如下所示 public static void main(String[] args) throws IOException { JsonObjectBuilder parserJSONObj = stanfordNLPParser(processedQuestion); System.out.println(

我正在尝试将stanford nlp输出通过管道传输到json。我尝试使用简单的json,一切都很好。当我尝试使用javax.json时,如下所示

public static void main(String[] args) throws IOException {

            JsonObjectBuilder parserJSONObj = stanfordNLPParser(processedQuestion);
            System.out.println(parserJSONObj.toString());

        }       

    public static JsonObjectBuilder stanfordNLPParser (String processedQuestion)throws IOException {

            Properties props = new Properties();
            props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, sentiment");
            StanfordCoreNLP pipeline = new StanfordCoreNLP(props);

            JsonObjectBuilder parserJSONObj = Json.createObjectBuilder(); 


            Annotation annotation = pipeline.process(processedQuestion);
            List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
            for (CoreMap sentence : sentences) {        
                for (CoreMap quesGentokens : sentence.get(TokensAnnotation.class)) {
                    String quesGenToken = quesGentokens.toString();
                    String quesGenPOS = quesGentokens.get(PartOfSpeechAnnotation.class);

                            parserJSONObj.add(quesGenToken, Json.createArrayBuilder()
                            .add(Json.createObjectBuilder()
                            .add("POS", quesGenPOS)));

                            parserJSONObj.build();              
                            System.out.println(parserJSONObj.toString());
                }

            }
            return parserJSONObj;           
        }
关于这一点,我现在有几个问题:

  • 即使添加到字符串也只显示内存位置
  • 是返回类型JsonObjectBuilder的右返回类型(考虑对Json的进一步操作)

  • 谢谢

    我想你应该从这个方法返回
    JsonObject
    。 您可以使用以下方法获取
    JsonObject

    JsonObject json = parserJSONObj.build();    
    

    如果您对这个json执行
    toString()
    ,您将在控制台上打印出实际的json

    您正在打印生成器,而不是生成器创建的JSON对象。
    JsonObject json = parserJSONObj.build();