Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java flexjson序列化组合JSON对象_Java_Json_Serialization_Flexjson - Fatal编程技术网

Java flexjson序列化组合JSON对象

Java flexjson序列化组合JSON对象,java,json,serialization,flexjson,Java,Json,Serialization,Flexjson,我有一个Java类,我想从该类的对象生成一个JSON字符串。然而,该班成员如下: /** * The set containing the footer texts */ public HeaderOrFooter[] footers = null; /** * The title of the word cloud */ public HeaderOrFooter title; /** * The subtitle of the word cloud */ public Heade

我有一个Java类,我想从该类的对象生成一个JSON字符串。然而,该班成员如下:

/**
 * The set containing the footer texts
 */
public HeaderOrFooter[] footers = null;
/**
 * The title of the word cloud
 */
public HeaderOrFooter title;
/**
 * The subtitle of the word cloud
 */
public HeaderOrFooter subTitle;
/**
 * The set of rectangles to be drawn
 */
public Rectangle[] rectangles;
/**
 * The set of round rectangles to be drawn
 */
public RoundRectangle[] roundRectangles;
/**
 * The set of lines to be drawn
 */
public Line[] lines;
/**
 * The set of polygons to be drawn
 */
public Polygon[] polygons;
/**
 * The set of words to be drawn
 */
public Word[] words;
我将对象转换为JSON的方法如下所示:

public String convertToJSON()
{
    flexjson.JSONSerializer jsonSerializer = new flexjson.JSONSerializer();
    jsonSerializer.exclude("class");
    jsonSerializer.exclude("subTitle.class");
    jsonSerializer.exclude("title.class");
    return jsonSerializer.serialize(this);
}

我使用的是
flexjson
及其
JSONSerializer
对象。我的问题是,它只将title和subTitle成员转换为JSON,而不转换数组。有人能告诉我如何将数组包含到JSON中吗?谢谢。

我已经弄明白了,这是正确的功能:

// Re-using the serializer as per "Thread Safety and Reuse"
// section of http://flexjson.sourceforge.net/
public static final flexjson.JSONSerializer jsonSerializer;
static {
    jsonSerializer = new flexjson.JSONSerializer().exclude("*.class");
}

public String toJSON() {
    return jsonSerializer.deepSerialize(this);
}

我已经弄明白了,这里是正确的函数:

// Re-using the serializer as per "Thread Safety and Reuse"
// section of http://flexjson.sourceforge.net/
public static final flexjson.JSONSerializer jsonSerializer;
static {
    jsonSerializer = new flexjson.JSONSerializer().exclude("*.class");
}

public String toJSON() {
    return jsonSerializer.deepSerialize(this);
}

您是否使用
新行[1]
或类似的方式为数组指定了一个值?然后填写
对象。数组中填充值。我可以分别序列化它们,但我想从包含它们的对象生成JSON。您是否已使用
新行[1]
或类似的方式为数组指定了值?然后填写
对象。数组中填充值。我可以分别序列化它们,但我想从包含它们的对象生成JSON。