I am using shopify iOS SDK(mobile-buy-sdk-ios) in react native to get login user's orders.Here is my code,
let query = Storefront.buildQuery { $0 .customer(customerAccessToken: token) { $0 .orders(first: count, reverse: true) { $0 .edges { $0 .node { $0 .id() .orderNumber() .totalPrice() .statusUrl() .lineItems(first: 25){ $0 .edges{ $0 .node{ $0 .title() .quantity() .variant{ $0 .id() .price() .title() .image{ $0 .originalSrc() } } } } } let task = self.client.queryGraphWith(query, cachePolicy: .networkOnly) { response, error in error.debugUserPrint() let userOrders = response.customer?.orders.edges[0].node; let res = try! JSONSerialization.data(withJSONObject: userOrders) completion([res])}
And I am getting this response in userOrders variable
<QueryRoot: ["customer": { orders = { edges = ( { node = { id = "Z2lkOi8vc2hvcGlmeS9PcmRlci8yMjY2NTM3NzU0NzEwP2tleT0zNWFiYzBkMjRmMDk3MjZlYzgzYjkwZDVlZGI5YjM4MA=="; lineItems = { edges = ( { node = { quantity = 1; title = "Gift wrapping"; variant = { id = "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC8xMjE3MzkzNjYyMzcwMg=="; image = { originalSrc = "https://cdn.shopify.com/s/files/1/2331/3377/products/Gift_Boxes_11_22_2017_Standard_1024x1024_60d01a1c-f665-4c9e-b80b-f6fda9167de3.jpg?v=1521444032"; }; price = "10.00"; title = "Default Title"; }; }; } ); }; orderNumber = 1040; statusUrl = "23313377/orders/11f378e7df2731521429f377015d2ec2/authenticate?key=35abc0d24f09726ec83b90d5edb9b380"; totalPrice = "10.00"; }; } ); };}]>)
this formate, so try to parse this data to JSON object to pass data from iOS function to javascript function. I have tried
JSONSerialization.data(withJSONObject: userOrders)
but it is not working. I just want to parse this data to JSON. I have also tried many other ways but no luck.
Thanks.