Selaa lähdekoodia

Fixed JSON serialization of models

Yentl Van Tendeloo 8 vuotta sitten
vanhempi
commit
040f7b93b1
1 muutettua tiedostoa jossa 7 lisäystä ja 2 poistoa
  1. 7 2
      core/core_algorithm.alc

+ 7 - 2
core/core_algorithm.alc

@@ -22,15 +22,22 @@ String function JSON_print(model : Element):
 	String type
 	String attr_key
 	Element attr_keys
+	Boolean first
 
 	result = "["
 	keys_m = dict_keys(model["model"])
+	first = True
 
 	while (read_nr_out(keys_m) > 0):
 		v_m = set_pop(keys_m)
 		type = read_type(model["metamodel"], read_type(model, v_m))
 
 		if (bool_or(type == "Class", type == "Association")):
+			if (bool_not(first)):
+				result = result + ","
+			else:
+				first = False
+
 			result = result + "{"
 			result = (((result + "\"id\": \"") + v_m) + "\"")
 			result = (((result + ",") + "\"type\": \"") + read_type(model, v_m)) + "\""
@@ -46,8 +53,6 @@ String function JSON_print(model : Element):
 
 			result = result + "}"
 
-			if (read_nr_out(keys_m) > 0):
-				result = result + ","
 	result = result + "]"
 
 	return result!