Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Gee;
- class Sas : GLib.Object {
- public int a {set;get;}
- // public ArrayList<int> arr {set;get;}
- public Sas(int a) {
- this.a = a;
- }
- }
- string serialize_ArrayList(Value val){
- if (val.type ().is_a (typeof (Gee.ArrayList))) {
- unowned Gee.ArrayList<GLib.Object> arraylist_value = val as Gee.ArrayList<GLib.Object>;
- if (arraylist_value != null) {
- var array = new Json.Array.sized (arraylist_value.size);
- foreach (var item in arraylist_value) {
- //message(@"$(Json.gobject_serialize (item))");
- array.add_element (Json.gobject_serialize (item));
- }
- var node = new Json.Node (Json.NodeType.ARRAY);
- node.set_array (array);
- return node.get_string();
- }
- else return "Error";
- }
- else return "Error";
- }
- public static int main(string[] args) {
- var arrlist = new ArrayList<Sas>.wrap({new Sas(1),new Sas(2),new Sas(4)});
- foreach (var item in arrlist) {
- message(@"$(item.a)\n");
- }
- Value arristVal = Value(typeof(ArrayList<Sas>));
- arristVal = arrlist;
- string strResult = serialize_ArrayList(arristVal);
- message(strResult);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement