Groovy web console

subscribe to the feed Subscribe
to this
site

store json

Published 2 months ago by edisson guerrero with tags Tailorsoft
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
import groovy.json.JsonSlurper 

def url_Json = new URL("https://www.tailorsoft.co/sample.json").getText();
def personMap = new JsonSlurper().parseText(url_Json)
def newPerson = new store(personMap)
List<Product> p=newPerson.products;
List<Order> o=newPerson.orders;
List<Item> i=newPerson.orders.items;
List<String> items=new ArrayList<String>();
Map<String,Integer> total  = new HashMap<String,Integer>();;

for(item in i){ 
for(un in item){
items.add(un);}
}


for(item in p){
for(ids in items){
if(item.id==ids.productId){
ids.quantity
}
}}



for(item in items){
if(!total.containsKey(item.id)){
total.put(item.id,item.quantity)
}
}
println(total);

for(item in newPerson.products.name){    
println "+--------------+---------+------------+";
println "| Product "+item+"      |  Orders "+"da" +" |      Total |";
println "+--------------+---------+------------+";
 }
public class store{
private List<Product> products;    
private List<Order> orders;
}
public class Product{
private String id;
private String name;
private double price;
}

public class Order{
private List<Item> items; 
private String id; 

public int findproductbyid(){
int x=0;
for (int i=0;i< items.size;i++){
println (items[i].productId)
if (items[i].productId){

}
}
return x;
}

}

public class Item{
private String productId; 
private int quantity; 
}