diff --git a/Services/OpenAtmosService.cs b/Services/OpenAtmosService.cs index 9acc29e..222e4c6 100644 --- a/Services/OpenAtmosService.cs +++ b/Services/OpenAtmosService.cs @@ -116,26 +116,40 @@ public async Task Get(Guid tag_mechanism_uuid) JSON += ", \n"; } var reactants = reactantProductListService.GetReactantsAsync(reaction.reactant_list_uuid).Result; - JSON += " \"reactants\": [ \n" + - " {\n"; - foreach (ReactantsProducts reactant in reactants) + if(reactants.Count != 0) { - JSON += " \"species name\": \"" + reactant.type + "\", \n"; - JSON += " \"coefficient\": \"" + reactant.quantity + "\" \n"; + JSON += " \"reactants\": [ \n" + + " {\n"; + foreach (ReactantsProducts reactant in reactants) + { + JSON += " \"species name\": \"" + reactant.type + "\", \n"; + JSON += " \"coefficient\": \"" + reactant.quantity + "\" \n"; + } + JSON += " }\n" + + " ], \n"; } - JSON += " }\n" + - " ], \n"; var products = reactantProductListService.GetProductsAsync(reaction.product_list_uuid).Result; - JSON += " \"products\": [ \n" + + + if(products.Count != 0) + { + JSON += " \"products\": [ \n" + " {\n"; - foreach (ReactantsProducts product in products) + foreach (ReactantsProducts product in products) + { + JSON += " \"species name\": \"" + product.type + "\", \n"; + JSON += " \"coefficient\": \"" + product.quantity + "\" \n"; + } + JSON += " }\n" + + " ]\n"; + } + + if(reactants.Count == 0 && products.Count == 0) { - JSON += " \"species name\": \"" + product.type + "\", \n"; - JSON += " \"coefficient\": \"" + product.quantity + "\" \n"; + JSON = JSON.Remove(JSON.LastIndexOf(',')); + JSON += "\n"; } - JSON += " }\n" + - " ]\n"; + JSON += " },\n"; } JSON = JSON.Remove(JSON.LastIndexOf(','));