stackoverflow team member I am having problem with displaying the json subarray data to my gridpanel my json data is below
{
"total": 11,
"success": true,
"employeetaskdetdata": [{
"subject": "Work in progress",
"employee": {
"username": "yogen",
"designation": {
"department": {
"company": {
"cmpname": "Kintu Designs Pvt ltd",
"cmptitle": "Kintu Designs Pvt ltd",
"cmpdesc": "<b>D-104 Toral Appartment Surat,<br>Timalyabad.</b>",
"cmpfax": "8128812153",
"cmpcontact": "8128812153",
"cmpwebsite": "www.kintudesigns.com",
"cmpemail1": "yaryan997#gmail.com",
"cmpemail2": "yaryan997#gmail.com",
"cmpcountry": "India",
"cmpstate": "Gujarat",
"cmpcity": "Surat",
"cmpaddress": "D-104 Toral Appartment Surat,\nTimalyabad.",
"cmplogo": "calendar.png",
"cmplogopath": "upload/images/",
"cmpcreatedby": 1,
"cmpcreatedon": 1335764510000,
"cmpmodifiedon": 1335764510000,
"cmpmodifiedby": 0,
"id": 1
},
"departname": "Programmer",
"createdby": 1,
"createdon": 1335764655000,
"modifiedby": 1,
"modifiedon": 1335764655000,
"departdescr": "<b>?Programmer</b>",
"id": 2
},
"createdby": 1,
"createdon": 1335764825000,
"modifiedby": 1,
"modifiedon": 1335764825000,
"designame": "Senior JAVA Programmer",
"desigdescr": "<b>?Senior JAVA Programmer</b>",
"id": 6
},
"createdby": 1,
"createdon": 1335765074000,
"modifiedby": 1,
"modifiedon": 1335765074000,
"dateofbirth": 1335810600000,
"joindate": 1337106600000,
"firstname": "Yogendra",
"surname": "Singh",
"gender": "M",
"marital": "U",
"nationality": "",
"contactno": "",
"mobileno": "",
"email": "",
"otheremail": "",
"fathername": "",
"mothername": "",
"accountno": "",
"salary": "",
"bank": {
"bankname": "ICICI Bank",
"bankaddress": "ICICI Bank Nanpura",
"id": 1
},
"address": "",
"id": 6,
"password": "123"
},
"todaysdate": "2012-05-05",
"createdby": 6,
"createdon": 1336203851000,
"modifiedby": 6,
"modifiedon": 1336203851000,
"project": {
"company": {
"cmpname": "Kintu Designs Pvt ltd",
"cmptitle": "Kintu Designs Pvt ltd",
"cmpdesc": "<b>D-104 Toral Appartment Surat,<br>Timalyabad.</b>",
"cmpfax": "8128812153",
"cmpcontact": "8128812153",
"cmpwebsite": "www.kintudesigns.com",
"cmpemail1": "yaryan997#gmail.com",
"cmpemail2": "yaryan997#gmail.com",
"cmpcountry": "India",
"cmpstate": "Gujarat",
"cmpcity": "Surat",
"cmpaddress": "D-104 Toral Appartment Surat,\nTimalyabad.",
"cmplogo": "calendar.png",
"cmplogopath": "upload/images/",
"cmpcreatedby": 1,
"cmpcreatedon": 1335764510000,
"cmpmodifiedon": 1335764510000,
"cmpmodifiedby": 0,
"id": 1
},
"createdby": 1,
"createdon": 1335765435000,
"modifiedby": 1,
"modifiedon": 1335765435000,
"projectname": "Project I",
"projecttitle": "Project I",
"projectdesc": "<b>Kintu Design Pvt ltd new Project I</b>",
"projectstart": 1335810600000,
"projectend": 1336761000000,
"id": 1
},
"task": {
"duration": 4.0,
"employee": [{
"username": "hiren",
"designation": {
"department": {
"company": {
"cmpname": "Kintu Designs Pvt ltd",
"cmptitle": "Kintu Designs Pvt ltd",
"cmpdesc": "<b>D-104 Toral Appartment Surat,<br>Timalyabad.</b>",
"cmpfax": "8128812153",
"cmpcontact": "8128812153",
"cmpwebsite": "www.kintudesigns.com",
"cmpemail1": "yaryan997#gmail.com",
"cmpemail2": "yaryan997#gmail.com",
"cmpcountry": "India",
"cmpstate": "Gujarat",
"cmpcity": "Surat",
"cmpaddress": "D-104 Toral Appartment Surat,\nTimalyabad.",
"cmplogo": "calendar.png",
"cmplogopath": "upload/images/",
"cmpcreatedby": 1,
"cmpcreatedon": 1335764510000,
"cmpmodifiedon": 1335764510000,
"cmpmodifiedby": 0,
"id": 1
},
"departname": "Programmer",
"createdby": 1,
"createdon": 1335764655000,
"modifiedby": 1,
"modifiedon": 1335764655000,
"departdescr": "<b>?Programmer</b>",
"id": 2
},
"createdby": 1,
"createdon": 1335764755000,
"modifiedby": 1,
"modifiedon": 1335764755000,
"designame": "Senior PHP Programmer",
"desigdescr": "<b>?Senior PHP Programmer</b>",
"id": 3
},
"createdby": 1,
"createdon": 1335765018000,
"modifiedby": 1,
"modifiedon": 1335765018000,
"dateofbirth": null,
"joindate": null,
"firstname": "Hiren",
"surname": "Patel",
"gender": "M",
"marital": "U",
"nationality": "",
"contactno": "",
"mobileno": "",
"email": "",
"otheremail": "",
"fathername": "",
"mothername": "",
"accountno": "",
"salary": "",
"bank": {
"bankname": "ICICI Bank",
"bankaddress": "ICICI Bank Nanpura",
"id": 1
},
"address": "",
"id": 4,
"password": "123"
}, {
"username": "yogen",
"designation": {
"department": {
"company": {
"cmpname": "Kintu Designs Pvt ltd",
"cmptitle": "Kintu Designs Pvt ltd",
"cmpdesc": "<b>D-104 Toral Appartment Surat,<br>Timalyabad.</b>",
"cmpfax": "8128812153",
"cmpcontact": "8128812153",
"cmpwebsite": "www.kintudesigns.com",
"cmpemail1": "yaryan997#gmail.com",
"cmpemail2": "yaryan997#gmail.com",
"cmpcountry": "India",
"cmpstate": "Gujarat",
"cmpcity": "Surat",
"cmpaddress": "D-104 Toral Appartment Surat,\nTimalyabad.",
"cmplogo": "calendar.png",
"cmplogopath": "upload/images/",
"cmpcreatedby": 1,
"cmpcreatedon": 1335764510000,
"cmpmodifiedon": 1335764510000,
"cmpmodifiedby": 0,
"id": 1
},
"departname": "Programmer",
"createdby": 1,
"createdon": 1335764655000,
"modifiedby": 1,
"modifiedon": 1335764655000,
"departdescr": "<b>?Programmer</b>",
"id": 2
},
"createdby": 1,
"createdon": 1335764825000,
"modifiedby": 1,
"modifiedon": 1335764825000,
"designame": "Senior JAVA Programmer",
"desigdescr": "<b>?Senior JAVA Programmer</b>",
"id": 6
},
"createdby": 1,
"createdon": 1335765074000,
"modifiedby": 1,
"modifiedon": 1335765074000,
"dateofbirth": 1335810600000,
"joindate": 1337106600000,
"firstname": "Yogendra",
"surname": "Singh",
"gender": "M",
"marital": "U",
"nationality": "",
"contactno": "",
"mobileno": "",
"email": "",
"otheremail": "",
"fathername": "",
"mothername": "",
"accountno": "",
"salary": "",
"bank": {
"bankname": "ICICI Bank",
"bankaddress": "ICICI Bank Nanpura",
"id": 1
},
"address": "",
"id": 6,
"password": "123"
}],
"createdby": 1,
"createdon": 1336460152000,
"modifiedby": 1,
"modifiedon": 1336460152000,
"project": {
"company": {
"cmpname": "Kintu Designs Pvt ltd",
"cmptitle": "Kintu Designs Pvt ltd",
"cmpdesc": "<b>D-104 Toral Appartment Surat,<br>Timalyabad.</b>",
"cmpfax": "8128812153",
"cmpcontact": "8128812153",
"cmpwebsite": "www.kintudesigns.com",
"cmpemail1": "yaryan997#gmail.com",
"cmpemail2": "yaryan997#gmail.com",
"cmpcountry": "India",
"cmpstate": "Gujarat",
"cmpcity": "Surat",
"cmpaddress": "D-104 Toral Appartment Surat,\nTimalyabad.",
"cmplogo": "calendar.png",
"cmplogopath": "upload/images/",
"cmpcreatedby": 1,
"cmpcreatedon": 1335764510000,
"cmpmodifiedon": 1335764510000,
"cmpmodifiedby": 0,
"id": 1
},
"createdby": 1,
"createdon": 1335765435000,
"modifiedby": 1,
"modifiedon": 1335765435000,
"projectname": "Project I",
"projecttitle": "Project I",
"projectdesc": "<b>Kintu Design Pvt ltd new Project I</b>",
"projectstart": 1335810600000,
"projectend": 1336761000000,
"id": 1
},
"percentdone": 55,
"durationunit": "d",
"startdate": 1336415400000,
"parentid": 2,
"taskindex": 0,
"taskname": "Sub Task 2 1",
"enddate": 1336761000000,
"priority": 2,
"id": 3,
"depth": 2
},
"percentdone": 20,
"totalworkedhrs": -9.5,
"starttime": "09:00:00",
"finishtime": "00:00:00",
"id": 1,
"description": "<b>Work in progress</b>",
"hours": 0,
"minutes": 30
}, {
"subject": "Work in progresss",
"employee": {
"username": "yogen",
"designation": {
"department": {
"company": {
"cmpname": "Kintu Designs Pvt ltd",
"cmptitle": "Kintu Designs Pvt ltd",
"cmpdesc": "<b>D-104 Toral Appartment Surat,<br>Timalyabad.</b>",
"cmpfax": "8128812153",
"cmpcontact": "8128812153",
"cmpwebsite": "www.kintudesigns.com",
"cmpemail1": "yaryan997#gmail.com",
"cmpemail2": "yaryan997#gmail.com",
"cmpcountry": "India",
"cmpstate": "Gujarat",
"cmpcity": "Surat",
"cmpaddress": "D-104 Toral Appartment Surat,\nTimalyabad.",
"cmplogo": "calendar.png",
"cmplogopath": "upload/images/",
"cmpcreatedby": 1,
"cmpcreatedon": 1335764510000,
"cmpmodifiedon": 1335764510000,
"cmpmodifiedby": 0,
"id": 1
},
"departname": "Programmer",
"createdby": 1,
"createdon": 1335764655000,
"modifiedby": 1,
"modifiedon": 1335764655000,
"departdescr": "<b>?Programmer</b>",
"id": 2
},
"createdby": 1,
"createdon": 1335764825000,
"modifiedby": 1,
"modifiedon": 1335764825000,
"designame": "Senior JAVA Programmer",
"desigdescr": "<b>?Senior JAVA Programmer</b>",
"id": 6
},
"createdby": 1,
"createdon": 1335765074000,
"modifiedby": 1,
"modifiedon": 1335765074000,
"dateofbirth": 1335810600000,
"joindate": 1337106600000,
"firstname": "Yogendra",
"surname": "Singh",
"gender": "M",
"marital": "U",
"nationality": "",
"contactno": "",
"mobileno": "",
"email": "",
"otheremail": "",
"fathername": "",
"mothername": "",
"accountno": "",
"salary": "",
"bank": {
"bankname": "ICICI Bank",
"bankaddress": "ICICI Bank Nanpura",
"id": 1
},
"address": "",
"id": 6,
"password": "123"
},
"todaysdate": "2012-05-05",
"createdby": 6,
"createdon": 1336204557000,
"modifiedby": 6,
"modifiedon": 1336204557000,
"project": {
"company": {
"cmpname": "Kintu Designs Pvt ltd",
"cmptitle": "Kintu Designs Pvt ltd",
"cmpdesc": "<b>D-104 Toral Appartment Surat,<br>Timalyabad.</b>",
"cmpfax": "8128812153",
"cmpcontact": "8128812153",
"cmpwebsite": "www.kintudesigns.com",
"cmpemail1": "yaryan997#gmail.com",
"cmpemail2": "yaryan997#gmail.com",
"cmpcountry": "India",
"cmpstate": "Gujarat",
"cmpcity": "Surat",
"cmpaddress": "D-104 Toral Appartment Surat,\nTimalyabad.",
"cmplogo": "calendar.png",
"cmplogopath": "upload/images/",
"cmpcreatedby": 1,
"cmpcreatedon": 1335764510000,
"cmpmodifiedon": 1335764510000,
"cmpmodifiedby": 0,
"id": 1
},
"createdby": 1,
"createdon": 1335765435000,
"modifiedby": 1,
"modifiedon": 1335765435000,
"projectname": "Project I",
"projecttitle": "Project I",
"projectdesc": "<b>Kintu Design Pvt ltd new Project I</b>",
"projectstart": 1335810600000,
"projectend": 1336761000000,
"id": 1
},
"task": {
"duration": 4.0,
"employee": [{
"username": "hiren",
"designation": {
"department": {
"company": {
"cmpname": "Kintu Designs Pvt ltd",
"cmptitle": "Kintu Designs Pvt ltd",
"cmpdesc": "<b>D-104 Toral Appartment Surat,<br>Timalyabad.</b>",
"cmpfax": "8128812153",
"cmpcontact": "8128812153",
"cmpwebsite": "www.kintudesigns.com",
"cmpemail1": "yaryan997#gmail.com",
"cmpemail2": "yaryan997#gmail.com",
"cmpcountry": "India",
"cmpstate": "Gujarat",
"cmpcity": "Surat",
"cmpaddress": "D-104 Toral Appartment Surat,\nTimalyabad.",
"cmplogo": "calendar.png",
"cmplogopath": "upload/images/",
"cmpcreatedby": 1,
"cmpcreatedon": 1335764510000,
"cmpmodifiedon": 1335764510000,
"cmpmodifiedby": 0,
"id": 1
},
"departname": "Programmer",
"createdby": 1,
"createdon": 1335764655000,
"modifiedby": 1,
"modifiedon": 1335764655000,
"departdescr": "<b>?Programmer</b>",
"id": 2
},
"createdby": 1,
"createdon": 1335764755000,
"modifiedby": 1,
"modifiedon": 1335764755000,
"designame": "Senior PHP Programmer",
"desigdescr": "<b>?Senior PHP Programmer</b>",
"id": 3
},
"createdby": 1,
"createdon": 1335765018000,
"modifiedby": 1,
"modifiedon": 1335765018000,
"dateofbirth": null,
"joindate": null,
"firstname": "Hiren",
"surname": "Patel",
"gender": "M",
"marital": "U",
"nationality": "",
"contactno": "",
"mobileno": "",
"email": "",
"otheremail": "",
"fathername": "",
"mothername": "",
"accountno": "",
"salary": "",
"bank": {
"bankname": "ICICI Bank",
"bankaddress": "ICICI Bank Nanpura",
"id": 1
},
"address": "",
"id": 4,
"password": "123"
}]
}
and my model is below
Ext.define('DEV.model.employeetaskdetModel', {
extend: 'Ext.data.Model',
fields : [
{ name: 'id'},
{ name: 'taskname', mapping:'task.taskname'},
{ name: 'firstname', mapping: 'employee.firstname'},
{ name: 'employee',type: 'auto'},
{ name: 'percentdone'}
]
});
and my grid panel columns are below
columns: [ {
xtype: 'gridcolumn',
dataIndex: 'percentdone',
text: 'Percent Done'
}, {
xtype: 'gridcolumn',
dataIndex: 'firstname',
text: 'First Name'
}]
I am not able to show the firstname in my gridPanel. But when I change the firstname column with below code it shows me the firstname gridpanel correctly.
{
xtype: 'gridcolumn',
dataIndex: 'employee',
text: 'User Name',
renderer: function (employee) {
var result = [];
employee = employee || [];
var value = employee.firstname;
if (value) {
result.push(value);
}
return result;
console.log(employee.firstname);
}
},
please suggest me why my gridpanel didn't show the firstname of user directly. What's the problem with my code. And why its showing the data when I add the renderer function.
I encountered a similar problem and solve it.
Mapping property is not required for mapping nested json data.
Model:
Ext.define("Model", {
extend: "Ext.data.Model",
fields: [
{name: "id", type: "int"},
{name: "name.name"},
{name: "phone", mapping: "name.phone"},
{name: "descr", type: "string", mapping:'description'}
]
});
Store with data that we will recieve from jsfiddle test echo ajax service:
var Store = Ext.create("Ext.data.Store", {
model: "Model",
autoLoad: true,
proxy: {
type: 'ajax',
url: '/echo/json/',
//
actionMethods: {read: 'POST'}, // echo ajax service required
extraParams: {
json: Ext.JSON.encode({
root: [
{id: 1, name: {name:"John", phone: "123"}, description:"Fapfapfap"},
{id: 2, name: {name:"Danny", phone: "234"}, description:"Boobooboo"},
{id: 3, name: {name:"Tom", phone: "345"}, description:"Tralala"},
{id: 4, name: {name:"Jane", phone: "456"}, description:"Ololo"},
]
})
},
reader: {
type: 'json',
root: 'root'
}
},
});
Grid:
Ext.create("Ext.grid.Panel", {
store: Store,
columns: [
{dataIndex: "id", header:"ID"},
{dataIndex: "name.name", header:"Name", flex: 1, editor: "textfield"},
{dataIndex: "phone", header:"Phone", flex: 1, editor: "textfield"},
{dataIndex: "descr", header: "Description", flex: 2, editor: "htmleditor"}
],
renderTo: Ext.getBody(),
});
This should work, if other problems is absent.
Here you can see work example http://jsfiddle.net/Fgh7z/1/
Related
i tried several times to fetch data, but it is not showing anything in the app,
here is the code base for the fetching Api data.
it is console logging.
the data is console logging in the metro
but while trying to render in the flat List it is not showing anything,instead a blank page is displayed.
the data is a nested objects.
import React, {useEffect, useState} from 'react';
import {FlatList, SafeAreaView, Text, View} from 'react-native';
export default FoodProductsApi = () => {
const [data, setData] = useState([]);
const getFoodApi = () => {
fetch(
'url',
{
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
countryName: 'India',
deliveryPincode: '5600100',
categoryType: 'Food',
}),
},
)
.then(response => response.json())
.then(json => {
setData(json.foodProducts);
console.log(json.foodProducts.categories);
})
.catch(error => {
console.error(error);
});
};
useEffect(() => {
getFoodApi();
}, []);
const keyExtractor = () => item => item.id;
return (
<SafeAreaView>
<Text>Name</Text>
<FlatList
data={data.foodProducts}
keyExtractor={keyExtractor}
renderItem={index => (
<View style={{flex: 1}}>
{index.data.foodProducts.map((i, v) => {
<Text>{i.categoryName}</Text>;
})}
</View>
)}
/>
</SafeAreaView>
);
};
this is the json Data
{
"responseCode": "200",
"responseMessage": "Successfull",
"foodProducts": {
"hubId": "610299e303be56ca3924971e",
"categories": [
{
"id": "61028aff294f460012c9101e",
"categoryName": "Kalyani Biryani",
"rankOrder": 6,
"status": "ACTIVE",
"createDate": "2021-07-29T11:03:27.345+0000",
"createdBy": null,
"updatedDate": "2021-07-29T13:17:55.270+0000",
"updateBy": "60b12c9e637d050012a7cf6b",
"zohoCategoryId": "594850000000019627",
"foodCategoryImage": "",
"categoryType": "Food",
"foodProducts": [
{
"id": "6102aa6f03be56ca3924b8f9",
"zohoItemId": "594850000000022886",
"productName": "Kalyani Chicken Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Non Veg",
"sku": "B035",
"mrp": 500,
"discountedPrice": 400,
"rankOrder": 6,
"description": null,
"hsnCode": "5006096",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:11.059+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:11.059+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Chicken",
"spiceLevel": "2",
"categoryType": "Food",
"availableStock": "58.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa7003be56ca3924b900",
"zohoItemId": "594850000000022946",
"productName": "Kalyani Egg Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Non Veg",
"sku": "B037",
"mrp": 300,
"discountedPrice": 290,
"rankOrder": 6,
"description": null,
"hsnCode": "5006097",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:11.348+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:11.348+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Egg",
"spiceLevel": "3",
"categoryType": "Food",
"availableStock": "56.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa7003be56ca3924b907",
"zohoItemId": "594850000000022915",
"productName": "Kalyani Mutton Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Non Veg",
"sku": "B036",
"mrp": 200,
"discountedPrice": 160,
"rankOrder": 6,
"description": null,
"hsnCode": "5006096",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:11.652+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:11.652+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Mutton",
"spiceLevel": "2",
"categoryType": "Food",
"availableStock": "52.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa7003be56ca3924b910",
"zohoItemId": "594850000000022977",
"productName": "Kalyani Paneer Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Veg",
"sku": "B038",
"mrp": 200,
"discountedPrice": 160,
"rankOrder": 12,
"description": null,
"hsnCode": "5006978",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:11.938+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:11.938+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": null,
"spiceLevel": "1",
"categoryType": "Food",
"availableStock": "51.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa7603be56ca3924b992",
"zohoItemId": "594850000000022762",
"productName": "Thalassery Chicken Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Non Veg",
"sku": "B031",
"mrp": 400,
"discountedPrice": 320,
"rankOrder": 17,
"description": null,
"hsnCode": "5006990",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:18.173+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:18.173+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Chicken",
"spiceLevel": "2",
"categoryType": "Food",
"availableStock": "128.000000",
"isFavorite": null,
"hubId": null
}
]
},
{
"id": "61028aa8294f460012c9101b",
"categoryName": "Bombay Biryani",
"rankOrder": 23,
"status": "ACTIVE",
"createDate": "2021-07-29T11:02:00.541+0000",
"createdBy": null,
"updatedDate": "2021-07-29T13:18:27.081+0000",
"updateBy": "60b12c9e637d050012a7cf6b",
"zohoCategoryId": "594850000000019605",
"foodCategoryImage": "",
"categoryType": "Food",
"foodProducts": [
{
"id": "6102aa6803be56ca3924b846",
"zohoItemId": "594850000000022576",
"productName": "Bombay Paneer Biryani",
"productImage": null,
"categoryId": "594850000000019605",
"vegNonVegFlag": "Veg",
"sku": "B024",
"mrp": 400,
"discountedPrice": 360,
"rankOrder": 10,
"description": null,
"hsnCode": "50090994",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:03.459+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:03.459+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": null,
"spiceLevel": "3",
"categoryType": "Food",
"availableStock": "130.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa6703be56ca3924b832",
"zohoItemId": "594850000000022607",
"productName": "Bomaby Fish Biryani",
"productImage": null,
"categoryId": "594850000000019605",
"vegNonVegFlag": "Non Veg",
"sku": "B025",
"mrp": 250,
"discountedPrice": 170,
"rankOrder": 11,
"description": null,
"hsnCode": "50090995",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:02.305+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:02.305+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Sea Food",
"spiceLevel": "2",
"categoryType": "Food",
"availableStock": "145.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa6803be56ca3924b83d",
"zohoItemId": "594850000000022638",
"productName": "Bombay Egg Biryani",
"productImage": null,
"categoryId": "594850000000019605",
"vegNonVegFlag": "Non Veg",
"sku": "B026",
"mrp": 240,
"discountedPrice": 210,
"rankOrder": 16,
"description": null,
"hsnCode": "5009099",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:02.885+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:02.885+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Egg",
"spiceLevel": "3",
"categoryType": "Food",
"availableStock": "-141.000000",
"isFavorite": null,
"hubId": null
}
]
},
Hope this Solves your Problem,
import React from 'react';
import {
SafeAreaView,
StyleSheet,
View,
Text,
FlatList
} from 'react-native';
const App = () => {
const [data, setData] = useState([]);
useEffect(() => {
getFoodApi();
}, []);
function getFoodApi()
{
setData({
"foodProducts": {
"hubId": "610299e303be56ca3924971e",
"categories": [
{
"id": "61028aff294f460012c9101e",
"categoryName": "Kalyani Biryani",
"rankOrder": 6,
"status": "ACTIVE",
"createDate": "2021-07-29T11:03:27.345+0000",
"createdBy": null,
"updatedDate": "2021-07-29T13:17:55.270+0000",
"updateBy": "60b12c9e637d050012a7cf6b",
"zohoCategoryId": "594850000000019627",
"foodCategoryImage": "",
"categoryType": "Food",
"foodProducts": [
{
"id": "6102aa6f03be56ca3924b8f9",
"zohoItemId": "594850000000022886",
"productName": "Kalyani Chicken Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Non Veg",
"sku": "B035",
"mrp": 500,
"discountedPrice": 400,
"rankOrder": 6,
"description": null,
"hsnCode": "5006096",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:11.059+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:11.059+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Chicken",
"spiceLevel": "2",
"categoryType": "Food",
"availableStock": "58.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa7003be56ca3924b900",
"zohoItemId": "594850000000022946",
"productName": "Kalyani Egg Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Non Veg",
"sku": "B037",
"mrp": 300,
"discountedPrice": 290,
"rankOrder": 6,
"description": null,
"hsnCode": "5006097",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:11.348+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:11.348+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Egg",
"spiceLevel": "3",
"categoryType": "Food",
"availableStock": "56.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa7003be56ca3924b907",
"zohoItemId": "594850000000022915",
"productName": "Kalyani Mutton Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Non Veg",
"sku": "B036",
"mrp": 200,
"discountedPrice": 160,
"rankOrder": 6,
"description": null,
"hsnCode": "5006096",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:11.652+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:11.652+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Mutton",
"spiceLevel": "2",
"categoryType": "Food",
"availableStock": "52.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa7003be56ca3924b910",
"zohoItemId": "594850000000022977",
"productName": "Kalyani Paneer Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Veg",
"sku": "B038",
"mrp": 200,
"discountedPrice": 160,
"rankOrder": 12,
"description": null,
"hsnCode": "5006978",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:11.938+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:11.938+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": null,
"spiceLevel": "1",
"categoryType": "Food",
"availableStock": "51.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa7603be56ca3924b992",
"zohoItemId": "594850000000022762",
"productName": "Thalassery Chicken Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Non Veg",
"sku": "B031",
"mrp": 400,
"discountedPrice": 320,
"rankOrder": 17,
"description": null,
"hsnCode": "5006990",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:18.173+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:18.173+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Chicken",
"spiceLevel": "2",
"categoryType": "Food",
"availableStock": "128.000000",
"isFavorite": null,
"hubId": null
}
]//food products[0]
}, //categories[0]
{
"id": "61028aa8294f460012c9101b",
"categoryName": "Bombay Biryani",
"rankOrder": 23,
"status": "ACTIVE",
"createDate": "2021-07-29T11:02:00.541+0000",
"createdBy": null,
"updatedDate": "2021-07-29T13:18:27.081+0000",
"updateBy": "60b12c9e637d050012a7cf6b",
"zohoCategoryId": "594850000000019605",
"foodCategoryImage": "",
"categoryType": "Food",
"foodProducts": [
{
"id": "6102aa6803be56ca3924b846",
"zohoItemId": "594850000000022576",
"productName": "Bombay Paneer Biryani",
"productImage": null,
"categoryId": "594850000000019605",
"vegNonVegFlag": "Veg",
"sku": "B024",
"mrp": 400,
"discountedPrice": 360,
"rankOrder": 10,
"description": null,
"hsnCode": "50090994",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:03.459+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:03.459+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": null,
"spiceLevel": "3",
"categoryType": "Food",
"availableStock": "130.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa6703be56ca3924b832",
"zohoItemId": "594850000000022607",
"productName": "Bomaby Fish Biryani",
"productImage": null,
"categoryId": "594850000000019605",
"vegNonVegFlag": "Non Veg",
"sku": "B025",
"mrp": 250,
"discountedPrice": 170,
"rankOrder": 11,
"description": null,
"hsnCode": "50090995",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:02.305+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:02.305+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Sea Food",
"spiceLevel": "2",
"categoryType": "Food",
"availableStock": "145.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa6803be56ca3924b83d",
"zohoItemId": "594850000000022638",
"productName": "Bombay Egg Biryani",
"productImage": null,
"categoryId": "594850000000019605",
"vegNonVegFlag": "Non Veg",
"sku": "B026",
"mrp": 240,
"discountedPrice": 210,
"rankOrder": 16,
"description": null,
"hsnCode": "5009099",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:02.885+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:02.885+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Egg",
"spiceLevel": "3",
"categoryType": "Food",
"availableStock": "-141.000000",
"isFavorite": null,
"hubId": null
}
]
}
]//categories
}//foodApi
})
}
return (
<SafeAreaView style={{flex:1}}>
<Text>Name</Text>
<FlatList
style={{flex:1}}
data={data.foodProducts.categories}
keyExtractor={(item,index)=>index.toString()}
renderItem={({ item, index }) => {
return (
<View style={{flex: 1}}>
<Text> categoreyname {item.categoryName}</Text>
{item.foodProducts.map(ele => {
return (
<Text style={{ paddingLeft: 5 }}> productName { ele.productName}</Text>
)
})}
</View>
)
}}
/>
</SafeAreaView>
);
};
const styles = StyleSheet.create({
});
export default App;
Flatlist will loop only array of object . in your code you have tried to loop objects (data.foodProducts).
Replace data={data.foodProducts} to data={data.foodproducts.categories}. Now it will loop, because its an array of objects.
Array of objects will be similar to this [{name:"React",age:5}]. This will be looped by flatlist
Objects will be similar to this {name:"react",age:5}. This will not looped by flatlist.
You can check whether data is an array or object using console.log(typeof data.foodproducts).
I have JSON file in Blob Storage that looks like this:
{
"Id": "****************************",
"Status": "OK",
"ProviderName": "Xero API Previewer",
"DateTimeUTC": "\/Date(1576561543598)\/",
"Invoices": [
{
"Type": "ACCPAY",
"InvoiceID": "*****************************",
"InvoiceNumber": "457489",
"Reference": "",
"Payments": [],
"CreditNotes": [],
"Prepayments": [],
"Overpayments": [],
"AmountDue": 0.00,
"AmountPaid": 0.00,
"AmountCredited": 0.00,
"CurrencyRate": 1.000000,
"IsDiscounted": false,
"HasAttachments": false,
"HasErrors": false,
"Contact": {
"ContactID": "************************************",
"Name": "********************",
"Addresses": [],
"Phones": [],
"ContactGroups": [],
"ContactPersons": [],
"HasValidationErrors": false
},
"DateString": "2102-11-26T00:00:00",
"Date": "\/Date(4193942400000+0000)\/",
"DueDateString": "2012-11-28T00:00:00",
"DueDate": "\/Date(1354060800000+0000)\/",
"Status": "VOIDED",
"LineAmountTypes": "Inclusive",
"LineItems": [
{
"Description": "Parking ",
"UnitAmount": 465.01,
"TaxType": "INPUT2",
"TaxAmount": 60.65,
"LineAmount": 465.01,
"AccountCode": "274",
"Tracking": [
{
"Name": "Region",
"Option": "New Zealand",
"TrackingCategoryID": "****************************************",
"Options": []
},
{
"Name": "Owner",
"Option": "Head Office",
"TrackingCategoryID": "***************************************",
"Options": []
}
],
"Quantity": 1.0000,
"LineItemID": "**************************************"
}
],
"SubTotal": 404.36,
"TotalTax": 60.65,
"Total": 465.01,
"UpdatedDateUTC": "\/Date(1355876228590+0000)\/",
"CurrencyCode": "NZD"
},
{
"Type": "ACCPAY",
"InvoiceID": "**************************************",
"InvoiceNumber": "176295-01",
"Reference": "",
"Payments": [
{
"PaymentID": "********************************************",
"Date": "\/Date(1576454400000+0000)\/",
"Amount": 137.43,
"Reference": "",
"CurrencyRate": 1.000000,
"HasAccount": false,
"HasValidationErrors": false
}
],
"CreditNotes": [],
"Prepayments": [],
"Overpayments": [],
"AmountDue": 0.00,
"AmountPaid": 137.43,
"AmountCredited": 0.00,
"CurrencyRate": 1.000000,
"IsDiscounted": false,
"HasAttachments": true,
"HasErrors": false,
"Contact": {
"ContactID": "************************************",
"Name": "InkWorks",
"Addresses": [],
"Phones": [],
"ContactGroups": [],
"ContactPersons": [],
"HasValidationErrors": false
},
"DateString": "2019-12-17T00:00:00",
"Date": "\/Date(1576540800000+0000)\/",
"DueDateString": "2020-01-20T00:00:00",
"DueDate": "\/Date(1579478400000+0000)\/",
"Status": "PAID",
"LineAmountTypes": "Inclusive",
"LineItems": [
{
"Description": "general stationery",
"UnitAmount": 137.43,
"TaxType": "INPUT2",
"TaxAmount": 17.93,
"LineAmount": 137.43,
"AccountCode": "273",
"Tracking": [
{
"Name": "Owner",
"Option": "Head Office",
"TrackingCategoryID": "******************************",
"Options": []
}
],
"Quantity": 1.0000,
"LineItemID": "****************************************"
}
],
"SubTotal": 119.50,
"TotalTax": 17.93,
"Total": 137.43,
"UpdatedDateUTC": "\/Date(1576524509820+0000)\/",
"CurrencyCode": "NZD",
"FullyPaidOnDate": "\/Date(1576454400000+0000)\/"
},
I want to store LineItems into a Table with columns as follows:
InvoiceID LineItemID Description LineAmount AccountCode Date
There can be multiple LineItems in a single invoice.
I managed to get the top level only with the following code.
WITH cte AS (
SELECT CAST (BulkColumn AS NVARCHAR(MAX)) AS jsonData
FROM
OPENROWSET(
BULK 'temp/XeroJson.json',
DATA_SOURCE = 'test'
-- FORMATFILE_DATA_SOURCE = 'test'
, SINGLE_CLOB
) AS blob
)
SELECT *
FROM cte
CROSS APPLY
OPENJSON(cte.jsonData) j
How can I make this work?
This is my test .json file, I placed it in my storage account :
{
"Id": "****************************",
"Status": "OK",
"ProviderName": "Xero API Previewer",
"DateTimeUTC": "\/Date(1576561543598)\/",
"Invoices":
[
{
"Type": "ACCPAY",
"InvoiceID": "123456",
"InvoiceNumber": "457489",
"Reference": "",
"Payments": [],
"CreditNotes": [],
"Prepayments": [],
"Overpayments": [],
"AmountDue": 0.00,
"AmountPaid": 0.00,
"AmountCredited": 0.00,
"CurrencyRate": 1.000000,
"IsDiscounted": false,
"HasAttachments": false,
"HasErrors": false,
"Contact": {
"ContactID": "************************************",
"Name": "********************",
"Addresses": [],
"Phones": [],
"ContactGroups": [],
"ContactPersons": [],
"HasValidationErrors": false
},
"DateString": "2102-11-26T00:00:00",
"Date": "\/Date(4193942400000+0000)\/",
"DueDateString": "2012-11-28T00:00:00",
"DueDate": "\/Date(1354060800000+0000)\/",
"Status": "VOIDED",
"LineAmountTypes": "Inclusive",
"LineItems": [{
"Description": "Parking ",
"UnitAmount": 465.01,
"TaxType": "INPUT2",
"TaxAmount": 60.65,
"LineAmount": 465.01,
"AccountCode": "274",
"Tracking": [{
"Name": "Region",
"Option": "New Zealand",
"TrackingCategoryID": "****************************************",
"Options": []
}, {
"Name": "Owner",
"Option": "Head Office",
"TrackingCategoryID": "***************************************",
"Options": []
}
],
"Quantity": 1.0000,
"LineItemID": "**************************************"
},
{
"Description": "Parking2 ",
"UnitAmount": 111.11,
"TaxType": "INPUT2",
"TaxAmount": 60.65,
"LineAmount": 465.01,
"AccountCode": "276",
"Tracking": [{
"Name": "Region",
"Option": "New Zealand",
"TrackingCategoryID": "****************************************",
"Options": []
}, {
"Name": "Owner",
"Option": "Head Office",
"TrackingCategoryID": "***************************************",
"Options": []
}
],
"Quantity": 1.0000,
"LineItemID": "**************************************"
}
],
"SubTotal": 404.36,
"TotalTax": 60.65,
"Total": 465.01,
"UpdatedDateUTC": "\/Date(1355876228590+0000)\/",
"CurrencyCode": "NZD"
},
{
"Type": "ACCPAY",
"InvoiceID": "1234567",
"InvoiceNumber": "176295-01",
"Reference": "",
"Payments": [{
"PaymentID": "********************************************",
"Date": "\/Date(1576454400000+0000)\/",
"Amount": 137.43,
"Reference": "",
"CurrencyRate": 1.000000,
"HasAccount": false,
"HasValidationErrors": false
}
],
"CreditNotes": [],
"Prepayments": [],
"Overpayments": [],
"AmountDue": 0.00,
"AmountPaid": 137.43,
"AmountCredited": 0.00,
"CurrencyRate": 1.000000,
"IsDiscounted": false,
"HasAttachments": true,
"HasErrors": false,
"Contact": {
"ContactID": "************************************",
"Name": "InkWorks",
"Addresses": [],
"Phones": [],
"ContactGroups": [],
"ContactPersons": [],
"HasValidationErrors": false
},
"DateString": "2019-12-17T00:00:00",
"Date": "\/Date(1576540800000+0000)\/",
"DueDateString": "2020-01-20T00:00:00",
"DueDate": "\/Date(1579478400000+0000)\/",
"Status": "PAID",
"LineAmountTypes": "Inclusive",
"LineItems": [{
"Description": "general stationery",
"UnitAmount": 137.43,
"TaxType": "INPUT2",
"TaxAmount": 17.93,
"LineAmount": 137.43,
"AccountCode": "273",
"Tracking": [{
"Name": "Owner",
"Option": "Head Office",
"TrackingCategoryID": "******************************",
"Options": []
}
],
"Quantity": 1.0000,
"LineItemID": "****************************************"
}
],
"SubTotal": 119.50,
"TotalTax": 17.93,
"Total": 137.43,
"UpdatedDateUTC": "\/Date(1576524509820+0000)\/",
"CurrencyCode": "NZD",
"FullyPaidOnDate": "\/Date(1576454400000+0000)\/"
}
]
}
As you can see the first invoice has two lineItems for demo here.
This is my sql script to exract from the json from storage :
CREATE DATABASE SCOPED CREDENTIAL AccessAzureInvoices
WITH
IDENTITY = 'SHARED ACCESS SIGNATURE'
-- REMOVE ? FROM THE BEGINNING OF THE SAS TOKEN
, SECRET = '<YOUR STORAGE SAS TOKEN>'
;
CREATE EXTERNAL DATA SOURCE MyAzureInvoices
WITH
( LOCATION = 'https://<YOUR STORAGE NAME>.blob.core.windows.net/<CONTAINER NAME WHERE YOUR JSON FILE IN>'
, CREDENTIAL = AccessAzureInvoices
, TYPE = BLOB_STORAGE
)
;
DECLARE #jsonVariable NVARCHAR(MAX);
set #jsonVariable = (select * from OPENROWSET(
BULK '<YOUR JSON FILE NAME>.json',
DATA_SOURCE = 'MyAzureInvoices',
SINGLE_CLOB
) AS blob)
select * from (
SELECT *
FROM OPENJSON(#jsonVariable,N'$.Invoices') WITH (
InvoiceID VARCHAR(200) N'$.InvoiceID',
Date VARCHAR(200) N'$.Date',
LineItems NVARCHAR(MAX) N'$.LineItems' as json
))as table1
CROSS APPLY OPENJSON(LineItems) with (
LineAmount VARCHAR(200) '$.LineAmount',
AccountCode VARCHAR(200)'$.AccountCode',
LineItemID VARCHAR(200) '$.LineItemID',
Description VARCHAR(200) '$.Description'
)
Result :
Hope it helps !
I am posting the following Order to the shopify api Order endpoint. The Order shows up in the shop and everything works as it should, except that the stock quantity of the variants in orders placed via the API are not decreased automatically by shopify. When I place an order within the admin console, they are decreased automatically. Shopify inventory tracking is turned on for the products. Any ideas would be greatly appreciated.
{
"order": {
"email": "someName#yahoo.com",
"financial_status": "paid",
"fulfillment_status": null,
"send_receipt": true,
"send_fulfillment_receipt": true,
"note": "Created by someName",
"line_items": [
{
"variant_id": 21718275463,
"quantity": 1,
"price": 99,
"requires_shipping": true,
"product_id": 6820646151
},
{
"variant_id": 21717700871,
"quantity": 1,
"price": 1000,
"requires_shipping": true,
"product_id": 6820646151
},
{
"variant_id": 21717690055,
"quantity": 1,
"price": 555,
"requires_shipping": true,
"product_id": 6821668807
}
],
"processing_method": "offsite",
"shipping_address": {
"first_name": "Chris",
"address1": "111 Love Road",
"phone": "9999999999",
"city": "St. Louis",
"zip": "63123",
"province": "MO",
"country": "United States",
"last_name": "Becker",
"name": "Chris Becker",
"country_code": "US",
"province_code": "MO"
},
"source_name": "someName",
"taxes_included": false,
"shipping_lines": [
{
"title": "standard",
"price": 0.00,
"code": null,
"source": "brand owner on shopify",
"carrier_identifier": null,
"tax_lines": null
}
],
"tags": "someName"
}
}
{
"variant": {
"id": 21718275463,
"product_id": 6820646151,
"title": "m / red",
"price": "99.00",
"sku": "",
"position": 2,
"grams": 0,
"inventory_policy": "deny",
"compare_at_price": "900.00",
"fulfillment_service": "manual",
"inventory_management": "shopify",
"option1": "m",
"option2": "red",
"option3": null,
"created_at": "2016-05-27T13:16:26-04:00",
"updated_at": "2016-05-28T13:28:20-04:00",
"taxable": false,
"barcode": "",
"image_id": 13217378823,
"inventory_quantity": 1,
"weight": 0,
"weight_unit": "lb",
"old_inventory_quantity": 1,
"requires_shipping": true
}
}
{
"variant": {
"id": 21717700871,
"product_id": 6820646151,
"title": "s / green",
"price": "1000.00",
"sku": "",
"position": 1,
"grams": 0,
"inventory_policy": "deny",
"compare_at_price": "1111.00",
"fulfillment_service": "manual",
"inventory_management": "shopify",
"option1": "s",
"option2": "green",
"option3": null,
"created_at": "2016-05-27T13:05:56-04:00",
"updated_at": "2016-05-28T12:17:22-04:00",
"taxable": true,
"barcode": "",
"image_id": 13160712135,
"inventory_quantity": 2,
"weight": 0,
"weight_unit": "lb",
"old_inventory_quantity": 2,
"requires_shipping": true
}
}
{
"variant": {
"id": 21717690055,
"product_id": 6821668807,
"title": "Default Title",
"price": "555.00",
"sku": "",
"position": 1,
"grams": 0,
"inventory_policy": "deny",
"compare_at_price": "666.00",
"fulfillment_service": "manual",
"inventory_management": "shopify",
"option1": "Default Title",
"option2": null,
"option3": null,
"created_at": "2016-05-27T13:05:39-04:00",
"updated_at": "2016-05-28T12:17:22-04:00",
"taxable": true,
"barcode": "",
"image_id": null,
"inventory_quantity": 2,
"weight": 0,
"weight_unit": "lb",
"old_inventory_quantity": 2,
"requires_shipping": true
}
}
You created a fake order using the API. Fake orders like that don't transact money or trigger the usual internal checks and balances without some extra effort. Maybe if you tried adding a fulfillment to the order, Shopify might ding inventory levels? Seems like something to try anyway.
I have a problem. When I try to make test my json, it says that it is not valid. But when I test it with online services, it reads it well.
The code I use to test if json is valid is:
NSString* stringRes = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
[NSJSONSerialization isValidJSONObject:stringRes];
Where stringRes is son string in NSString format.(From data response)
JSON :
{
"response": [
9,
{
"id": 47,
"from_id": 211551056,
"to_id": -101815039,
"date": 1442585775,
"post_type": "post",
"text": "Кто на андроид кодит хоть немножк ? Хотя бы hello world ?",
"can_edit": 1,
"created_by": 211551056,
"can_delete": 1,
"post_source": {
"type": "api",
"platform": "iphone"
},
"comments": {
"count": 0,
"can_post": 1
},
"likes": {
"count": 0,
"user_likes": 0,
"can_like": 1,
"can_publish": 0
},
"reposts": {
"count": 0,
"user_reposted": 0
},
"online": 1,
"reply_count": 0
},
{
"id": 43,
"from_id": 217702824,
"to_id": -101815039,
"date": 1442555658,
"post_type": "post",
"text": "Учебник по географии",
"can_delete": 1,
"attachment": {
"type": "doc",
"doc": {
"did": 419802605,
"owner_id": 217702824,
"title": "11_geo_m_2012.pdf",
"size": 92318316,
"ext": "pdf",
"url": "http://vk.com/doc217702824_419802605?hash=5eb9bb9753a6f88e88&dl=fcadca27db5845a002&api=1",
"access_key": "8e4218746055687cc2"
}
},
"attachments": [
{
"type": "doc",
"doc": {
"did": 419802605,
"owner_id": 217702824,
"title": "11_geo_m_2012.pdf",
"size": 92318316,
"ext": "pdf",
"url": "http://vk.com/doc217702824_419802605?hash=5eb9bb9753a6f88e88&dl=fcadca27db5845a002&api=1",
"access_key": "8e4218746055687cc2"
}
}
],
"post_source": {
"type": "api",
"platform": "android"
},
"comments": {
"count": 0,
"can_post": 1
},
"likes": {
"count": 3,
"user_likes": 0,
"can_like": 1,
"can_publish": 0
},
"reposts": {
"count": 0,
"user_reposted": 0
},
"online": 0,
"reply_count": 0
},
{
"id": 37,
"from_id": 211551056,
"to_id": -101815039,
"date": 1442502437,
"post_type": "post",
"text": "У кого айфон, + в комменты",
"can_delete": 1,
"attachment": {
"type": "poll",
"poll": {
"poll_id": 195892301,
"question": "Удобно смотреть расписание ?(На сайте)"
}
},
"attachments": [
{
"type": "poll",
"poll": {
"poll_id": 195892301,
"question": "Удобно смотреть расписание ?(На сайте)"
}
}
],
"post_source": {
"type": "api",
"platform": "iphone"
},
"comments": {
"count": 5,
"can_post": 1
},
"likes": {
"count": 0,
"user_likes": 0,
"can_like": 1,
"can_publish": 0
},
"reposts": {
"count": 0,
"user_reposted": 0
},
"online": 1,
"reply_count": 5
},
{
"id": 36,
"from_id": 249011483,
"to_id": -101815039,
"date": 1442500757,
"post_type": "post",
"text": "Домашку выложить не забудьте 👌👆",
"can_delete": 1,
"post_source": {
"type": "api",
"platform": "iphone"
},
"comments": {
"count": 0,
"can_post": 1
},
"likes": {
"count": 1,
"user_likes": 0,
"can_like": 1,
"can_publish": 0
},
"reposts": {
"count": 0,
"user_reposted": 0
},
"online": 1,
"reply_count": 0
},
{
"id": 28,
"from_id": 211551056,
"to_id": -101815039,
"date": 1442306249,
"post_type": "post",
"text": "",
"can_delete": 1,
"media": {
"type": "photo",
"owner_id": -101815039,
"item_id": 381477357,
"thumb_src": "http://cs624425.vk.me/v624425056/49e35/_w_YDirrrQU.jpg"
},
"attachment": {
"type": "photo",
"photo": {
"pid": 381477357,
"aid": -8,
"owner_id": -101815039,
"user_id": 211551056,
"src": "http://cs624425.vk.me/v624425056/49e35/_w_YDirrrQU.jpg",
"src_big": "http://cs624425.vk.me/v624425056/49e36/439edT8aXks.jpg",
"src_small": "http://cs624425.vk.me/v624425056/49e34/uLxZj9yF1F4.jpg",
"src_xbig": "http://cs624425.vk.me/v624425056/49e37/nhvaG43cV-Y.jpg",
"src_xxbig": "http://cs624425.vk.me/v624425056/49e38/Ox54xM039hg.jpg",
"width": 960,
"height": 720,
"text": "",
"created": 1442306250,
"lat": 55.785025,
"long": 37.706605,
"post_id": 28,
"access_key": "454823aa95a2ee9fbc"
}
},
"attachments": [
{
"type": "photo",
"photo": {
"pid": 381477357,
"aid": -8,
"owner_id": -101815039,
"user_id": 211551056,
"src": "http://cs624425.vk.me/v624425056/49e35/_w_YDirrrQU.jpg",
"src_big": "http://cs624425.vk.me/v624425056/49e36/439edT8aXks.jpg",
"src_small": "http://cs624425.vk.me/v624425056/49e34/uLxZj9yF1F4.jpg",
"src_xbig": "http://cs624425.vk.me/v624425056/49e37/nhvaG43cV-Y.jpg",
"src_xxbig": "http://cs624425.vk.me/v624425056/49e38/Ox54xM039hg.jpg",
"width": 960,
"height": 720,
"text": "",
"created": 1442306250,
"lat": 55.785025,
"long": 37.706605,
"post_id": 28,
"access_key": "454823aa95a2ee9fbc"
}
}
],
"post_source": {
"type": "api",
"platform": "iphone"
},
"comments": {
"count": 0,
"can_post": 1
},
"likes": {
"count": 1,
"user_likes": 0,
"can_like": 1,
"can_publish": 0
},
"reposts": {
"count": 0,
"user_reposted": 0
},
"online": 1,
"reply_count": 0
},
{
"id": 27,
"from_id": 211551056,
"to_id": -101815039,
"date": 1442306164,
"post_type": "post",
"text": "",
"can_delete": 1,
"media": {
"type": "photo",
"owner_id": -101815039,
"item_id": 381477244,
"thumb_src": "http://cs624425.vk.me/v624425056/49e2c/kttj5pUpjTk.jpg"
},
"attachment": {
"type": "photo",
"photo": {
"pid": 381477244,
"aid": -8,
"owner_id": -101815039,
"user_id": 211551056,
"src": "http://cs624425.vk.me/v624425056/49e2c/kttj5pUpjTk.jpg",
"src_big": "http://cs624425.vk.me/v624425056/49e2d/ihg9szTvLew.jpg",
"src_small": "http://cs624425.vk.me/v624425056/49e2b/GpS0xwCa66c.jpg",
"src_xbig": "http://cs624425.vk.me/v624425056/49e2e/pe4tflJokqs.jpg",
"src_xxbig": "http://cs624425.vk.me/v624425056/49e2f/7vkU8nUyNxc.jpg",
"width": 960,
"height": 720,
"text": "",
"created": 1442306166,
"lat": 55.785083,
"long": 37.711116,
"post_id": 27,
"access_key": "cb01ac011f4abbc0af"
}
},
"attachments": [
{
"type": "photo",
"photo": {
"pid": 381477244,
"aid": -8,
"owner_id": -101815039,
"user_id": 211551056,
"src": "http://cs624425.vk.me/v624425056/49e2c/kttj5pUpjTk.jpg",
"src_big": "http://cs624425.vk.me/v624425056/49e2d/ihg9szTvLew.jpg",
"src_small": "http://cs624425.vk.me/v624425056/49e2b/GpS0xwCa66c.jpg",
"src_xbig": "http://cs624425.vk.me/v624425056/49e2e/pe4tflJokqs.jpg",
"src_xxbig": "http://cs624425.vk.me/v624425056/49e2f/7vkU8nUyNxc.jpg",
"width": 960,
"height": 720,
"text": "",
"created": 1442306166,
"lat": 55.785083,
"long": 37.711116,
"post_id": 27,
"access_key": "cb01ac011f4abbc0af"
}
}
],
"post_source": {
"type": "api",
"platform": "iphone"
},
"comments": {
"count": 0,
"can_post": 1
},
"likes": {
"count": 1,
"user_likes": 0,
"can_like": 1,
"can_publish": 0
},
"reposts": {
"count": 0,
"user_reposted": 0
},
"online": 1,
"reply_count": 0
},
{
"id": 16,
"from_id": 249011483,
"to_id": -101815039,
"date": 1442069345,
"post_type": "post",
"text": "Кто нибудь сделал алгебру ?",
"can_delete": 1,
"post_source": {
"type": "api",
"platform": "iphone"
},
"comments": {
"count": 6,
"can_post": 1
},
"likes": {
"count": 3,
"user_likes": 0,
"can_like": 1,
"can_publish": 0
},
"reposts": {
"count": 0,
"user_reposted": 0
},
"online": 1,
"reply_count": 6
},
{
"id": 9,
"from_id": 127082413,
"to_id": -101815039,
"date": 1441911418,
"post_type": "post",
"text": "Официальная информациия ,староста нашей группы Александр Кондор!",
"can_delete": 1,
"post_source": {
"type": "api",
"platform": "android"
},
"comments": {
"count": 6,
"can_post": 1
},
"likes": {
"count": 2,
"user_likes": 0,
"can_like": 1,
"can_publish": 0
},
"reposts": {
"count": 0,
"user_reposted": 0
},
"online": 1,
"reply_count": 6
},
{
"id": 1,
"from_id": -101815039,
"to_id": -101815039,
"date": 1441656588,
"post_type": "post",
"text": "",
"can_delete": 1,
"can_pin": 1,
"media": {
"type": "photo",
"owner_id": -101815039,
"item_id": 380592775,
"thumb_src": "http://cs629111.vk.me/v629111548/e99f/DcV1yHZK1fw.jpg"
},
"attachment": {
"type": "photo",
"photo": {
"pid": 380592775,
"aid": -6,
"owner_id": -101815039,
"user_id": 100,
"src": "http://cs629111.vk.me/v629111548/e99f/DcV1yHZK1fw.jpg",
"src_big": "http://cs629111.vk.me/v629111548/e9a0/Qf8q8PpH7Jg.jpg",
"src_small": "http://cs629111.vk.me/v629111548/e99e/2Jq8e-0SptQ.jpg",
"src_xbig": "http://cs629111.vk.me/v629111548/e9a1/Uha0MvOoVCU.jpg",
"src_xxbig": "http://cs629111.vk.me/v629111548/e9a2/v8hqUldA6Kk.jpg",
"width": 730,
"height": 1024,
"text": "",
"created": 1441656588,
"post_id": 1
}
},
"attachments": [
{
"type": "photo",
"photo": {
"pid": 380592775,
"aid": -6,
"owner_id": -101815039,
"user_id": 100,
"src": "http://cs629111.vk.me/v629111548/e99f/DcV1yHZK1fw.jpg",
"src_big": "http://cs629111.vk.me/v629111548/e9a0/Qf8q8PpH7Jg.jpg",
"src_small": "http://cs629111.vk.me/v629111548/e99e/2Jq8e-0SptQ.jpg",
"src_xbig": "http://cs629111.vk.me/v629111548/e9a1/Uha0MvOoVCU.jpg",
"src_xxbig": "http://cs629111.vk.me/v629111548/e9a2/v8hqUldA6Kk.jpg",
"width": 730,
"height": 1024,
"text": "",
"created": 1441656588,
"post_id": 1
}
}
],
"post_source": {
"type": "api",
"platform": "android",
"data": "profile_photo"
},
"comments": {
"count": 0,
"can_post": 1
},
"likes": {
"count": 0,
"user_likes": 0,
"can_like": 1,
"can_publish": 0
},
"reposts": {
"count": 0,
"user_reposted": 0
},
"online": 1,
"reply_count": 0
}
]
}
UPD: Solved by using
NSData* data = [stringRes dataUsingEncoding:NSUTF8StringEncoding];
isValidJSONObject tests if a JSON object (a NSDictionary or NSArray) can be successfully converted to JSON data.
It is not for testing if an NSData object contains valid JSON data. To test for valid JSON data you just call
[NSJSONSerialization JSONObjectWithData:data ...]
and check if the return value is nil or not.
My JSON url is http://api.kivaws.org/v1/loans/search.json?status=fundraising
My Objective- code displays page_size : 20 using the following code
NSData *allCourseData=[[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:#"http://api.kivaws.org/v1/loans/search.json?status=fundraising"]];
NSError *error;
NSMutableDictionary *JsonObject = [NSJSONSerialization
JSONObjectWithData:allCourseData options:NSJSONReadingMutableContainers
error:&error];
//NSLog(#"json object is: - %#", JsonObject);
//Print Page size
NSLog(#"Page size is %#", [[JsonObject objectForKey:#"paging"] objectForKey:#"page_size"]);
My problem is how do i loop to Loans array to display the following
Example it will display name, display ALL languages, status so output will look like
============================
Name : "Maria Luisa"
languages: es,en
status : "fundraising"
sector : "Retail"
location
country_code : "NI"
Name : "Florence"
languages: en
status : "fundraising"
sector : "Retail"
location
country_code : "KE"
MyJSON Feed
{
"paging": {
"page": 1,
"total": 7279,
"page_size": 20,
"pages": 364
},
"loans": [
{
"id": 941933,
"name": "Maria Luisa",
"description": {
"languages": [
"es",
"en"
]
},
"status": "fundraising",
"funded_amount": 0,
"basket_amount": 0,
"image": {
"id": 1969857,
"template_id": 1
},
"activity": "General Store",
"sector": "Retail",
"use": "to buy rice, chicken, sausages, corn, beans, and sugar.",
"location": {
"country_code": "NI",
"country": "Nicaragua",
"town": "Esteli",
"geo": {
"level": "town",
"pairs": "13.166667 -86.333333",
"type": "point"
}
},
"partner_id": 176,
"posted_date": "2015-09-04T09:20:02Z",
"planned_expiration_date": "2015-10-04T09:20:02Z",
"loan_amount": 600,
"borrower_count": 1,
"lender_count": 0,
"bonus_credit_eligibility": true,
"tags": []
},
{
"id": 942181,
"name": "Florence",
"description": {
"languages": [
"en"
]
},
"status": "fundraising",
"funded_amount": 0,
"basket_amount": 0,
"image": {
"id": 1970181,
"template_id": 1
},
"activity": "Retail",
"sector": "Retail",
"use": "to buy more stocks of maize.",
"location": {
"country_code": "KE",
"country": "Kenya",
"town": "Bondo",
"geo": {
"level": "town",
"pairs": "1 38",
"type": "point"
}
},
"partner_id": 138,
"posted_date": "2015-09-04T09:10:08Z",
"planned_expiration_date": "2015-10-04T09:10:08Z",
"loan_amount": 200,
"borrower_count": 1,
"lender_count": 0,
"bonus_credit_eligibility": true,
"tags": []
},
{
"id": 942146,
"name": "Naziha",
"description": {
"languages": [
"en"
]
},
"status": "fundraising",
"funded_amount": 0,
"basket_amount": 0,
"image": {
"id": 1970129,
"template_id": 1
},
"activity": "Fruits & Vegetables",
"sector": "Food",
"use": "to increase her merchandise and diversify the products in her shop.",
"location": {
"country_code": "LB",
"country": "Lebanon",
"town": "Ain Al Helwi",
"geo": {
"level": "town",
"pairs": "33.833333 35.833333",
"type": "point"
}
},
"partner_id": 77,
"posted_date": "2015-09-04T09:10:02Z",
"planned_expiration_date": "2015-10-04T09:10:02Z",
"loan_amount": 2500,
"borrower_count": 1,
"lender_count": 0,
"bonus_credit_eligibility": true,
"tags": []
},
{
"id": 942180,
"name": "Sokean's Group",
"description": {
"languages": [
"en"
]
},
"status": "fundraising",
"funded_amount": 0,
"basket_amount": 0,
"image": {
"id": 1970180,
"template_id": 1
},
"activity": "Home Appliances",
"sector": "Personal Use",
"themes": [
"Water and Sanitation"
],
"use": "to buy a water filter to provide safe drinking water for her family.",
"location": {
"country_code": "KH",
"country": "Cambodia",
"town": "Kandal",
"geo": {
"level": "town",
"pairs": "13 105",
"type": "point"
}
},
"partner_id": 311,
"posted_date": "2015-09-04T09:00:05Z",
"planned_expiration_date": "2015-10-04T09:00:05Z",
"loan_amount": 100,
"borrower_count": 2,
"lender_count": 0,
"bonus_credit_eligibility": false,
"tags": [
{
"name": "volunteer_like"
}
]
},
{
"id": 941931,
"name": "Lucia Ingrid",
"description": {
"languages": [
"es",
"en"
]
},
"status": "fundraising",
"funded_amount": 0,
"basket_amount": 0,
"image": {
"id": 1969852,
"template_id": 1
},
"activity": "Personal Housing Expenses",
"sector": "Housing",
"themes": [
"Conflict Zones"
],
"use": "to invest in: electric wires, a fuse box, sockets, and labor to install electricity in her home.",
"location": {
"country_code": "SV",
"country": "El Salvador",
"geo": {
"level": "country",
"pairs": "13.833333 -88.916667",
"type": "point"
}
},
"partner_id": 81,
"posted_date": "2015-09-04T09:00:03Z",
"planned_expiration_date": "2015-10-04T09:00:03Z",
"loan_amount": 500,
"borrower_count": 1,
"lender_count": 0,
"bonus_credit_eligibility": true,
"tags": []
},
{
"id": 941930,
"name": "La Manzanita Group",
"description": {
"languages": [
"es",
"en"
]
},
"status": "fundraising",
"funded_amount": 0,
"basket_amount": 0,
"image": {
"id": 1969849,
"template_id": 1
},
"activity": "Fruits & Vegetables",
"sector": "Food",
"use": "to invest in buying papayas and nance berries in bulk.",
"location": {
"country_code": "NI",
"country": "Nicaragua",
"town": "Masaya",
"geo": {
"level": "town",
"pairs": "11.966667 -86.1",
"type": "point"
}
},
"partner_id": 120,
"posted_date": "2015-09-04T08:50:02Z",
"planned_expiration_date": "2015-10-04T08:50:02Z",
"loan_amount": 450,
"borrower_count": 3,
"lender_count": 0,
"bonus_credit_eligibility": true,
"tags": []
},
{
"id": 941926,
"name": "Manuel",
"description": {
"languages": [
"es",
"en"
]
},
"status": "fundraising",
"funded_amount": 0,
"basket_amount": 0,
"image": {
"id": 1969843,
"template_id": 1
},
"activity": "Property",
"sector": "Housing",
"use": "to buy two acres of land.",
"location": {
"country_code": "GT",
"country": "Guatemala",
"town": "Solola",
"geo": {
"level": "town",
"pairs": "14.666667 -91.25",
"type": "point"
}
},
"partner_id": 246,
"posted_date": "2015-09-04T08:10:02Z",
"planned_expiration_date": "2015-10-04T08:10:02Z",
"loan_amount": 800,
"borrower_count": 1,
"lender_count": 0,
"bonus_credit_eligibility": true,
"tags": [
{
"name": "volunteer_like"
}
]
},
{
"id": 942158,
"name": "Tahira",
"description": {
"languages": [
"en"
]
},
"status": "fundraising",
"funded_amount": 150,
"basket_amount": 0,
"image": {
"id": 1969161,
"template_id": 1
},
"activity": "Sewing",
"sector": "Services",
"themes": [
"Underfunded Areas"
],
"use": "buy a new sewing machine for her clothes sewing center.",
"location": {
"country_code": "PK",
"country": "Pakistan",
"town": "Multan",
"geo": {
"level": "town",
"pairs": "30.195556 71.475278",
"type": "point"
}
},
"partner_id": 247,
"posted_date": "2015-09-04T07:00:05Z",
"planned_expiration_date": "2015-10-04T07:00:05Z",
"loan_amount": 400,
"borrower_count": 1,
"lender_count": 5,
"bonus_credit_eligibility": false,
"tags": []
},
{
"id": 942166,
"name": "Sareoun's Group",
"description": {
"languages": [
"en"
]
},
"status": "fundraising",
"funded_amount": 0,
"basket_amount": 0,
"image": {
"id": 1970161,
"template_id": 1
},
"activity": "Home Appliances",
"sector": "Personal Use",
"themes": [
"Water and Sanitation"
],
"use": "to buy a water filter to provide safe drinking water for their family.\t.",
"location": {
"country_code": "KH",
"country": "Cambodia",
"town": "Kandal",
"geo": {
"level": "town",
"pairs": "13 105",
"type": "point"
}
},
"partner_id": 311,
"posted_date": "2015-09-04T07:00:05Z",
"planned_expiration_date": "2015-10-04T07:00:05Z",
"loan_amount": 225,
"borrower_count": 5,
"lender_count": 0,
"bonus_credit_eligibility": false,
"tags": []
},
{
"id": 942156,
"name": "Aiza",
"description": {
"languages": [
"en"
]
},
"status": "fundraising",
"funded_amount": 75,
"basket_amount": 0,
"image": {
"id": 1970147,
"template_id": 1
},
"activity": "Farming",
"sector": "Agriculture",
"use": "to buy fertilizers and other farm supplies",
"location": {
"country_code": "PH",
"country": "Philippines",
"town": "Kalibo, Aklan",
"geo": {
"level": "town",
"pairs": "13 122",
"type": "point"
}
},
"partner_id": 145,
"posted_date": "2015-09-04T07:00:03Z",
"planned_expiration_date": "2015-10-04T07:00:03Z",
"loan_amount": 225,
"borrower_count": 1,
"lender_count": 2,
"bonus_credit_eligibility": true,
"tags": []
},
{
"id": 942160,
"name": "Magu Group",
"description": {
"languages": [
"en"
]
},
"status": "fundraising",
"funded_amount": 0,
"basket_amount": 0,
"image": {
"id": 1970122,
"template_id": 1
},
"activity": "Used Clothing",
"sector": "Clothing",
"use": "to buy fast moving second hand clothes to meet her customer requirement.",
"location": {
"country_code": "TZ",
"country": "Tanzania",
"town": "Dar es Salaam",
"geo": {
"level": "town",
"pairs": "-6.8 39.283333",
"type": "point"
}
},
"partner_id": 87,
"posted_date": "2015-09-04T07:00:02Z",
"planned_expiration_date": "2015-10-04T07:00:02Z",
"loan_amount": 525,
"borrower_count": 2,
"lender_count": 0,
"bonus_credit_eligibility": true,
"tags": []
},
{
"id": 942142,
"name": "Mwanamiraji",
"description": {
"languages": [
"en"
]
},
"status": "fundraising",
"funded_amount": 0,
"basket_amount": 0,
"image": {
"id": 1970130,
"template_id": 1
},
"activity": "Food Stall",
"sector": "Food",
"use": "to purchase a stock of tomatoes, onions, mangoes and green vegetables for resale",
"location": {
"country_code": "KE",
"country": "Kenya",
"town": "Tiribe",
"geo": {
"level": "town",
"pairs": "1 38",
"type": "point"
}
},
"partner_id": 164,
"posted_date": "2015-09-04T06:30:04Z",
"planned_expiration_date": "2015-10-04T06:30:04Z",
"loan_amount": 200,
"borrower_count": 1,
"lender_count": 0,
"bonus_credit_eligibility": true,
"tags": []
},
{
"id": 940065,
"name": "Tubogorane Group",
"description": {
"languages": [
"fr",
"en"
]
},
"status": "fundraising",
"funded_amount": 0,
"basket_amount": 0,
"image": {
"id": 1967147,
"template_id": 1
},
"activity": "Food",
"sector": "Food",
"themes": [
"Conflict Zones"
],
"use": "to increase his working capital and buy a large quantity of fruit and cheese for sale.",
"location": {
"country_code": "BI",
"country": "Burundi",
"town": "Bujumbura",
"geo": {
"level": "town",
"pairs": "-3.5 30",
"type": "point"
}
},
"partner_id": 162,
"posted_date": "2015-09-04T06:20:05Z",
"planned_expiration_date": "2015-10-04T06:20:05Z",
"loan_amount": 3050,
"borrower_count": 19,
"lender_count": 0,
"bonus_credit_eligibility": false,
"tags": []
},
{
"id": 940076,
"name": "Wend Loiim Taore 2 Group",
"description": {
"languages": [
"fr",
"en"
]
},
"status": "fundraising",
"funded_amount": 50,
"basket_amount": 0,
"image": {
"id": 1967173,
"template_id": 1
},
"activity": "Clothing Sales",
"sector": "Clothing",
"use": "to buy pagnes (traditional, wrap-around clothing) and soap for sale.",
"location": {
"country_code": "BF",
"country": "Burkina Faso",
"town": "Ouagadougou Boulmiougou",
"geo": {
"level": "town",
"pairs": "13 -2",
"type": "point"
}
},
"partner_id": 398,
"posted_date": "2015-09-04T06:20:05Z",
"planned_expiration_date": "2015-10-04T06:20:05Z",
"loan_amount": 1850,
"borrower_count": 5,
"lender_count": 2,
"bonus_credit_eligibility": false,
"tags": []
},
{
"id": 942145,
"name": "Adham",
"description": {
"languages": [
"en"
]
},
"status": "fundraising",
"funded_amount": 25,
"basket_amount": 0,
"image": {
"id": 1970127,
"template_id": 1
},
"activity": "Barber Shop",
"sector": "Services",
"use": "to buy new salon equipment.",
"location": {
"country_code": "PS",
"country": "Palestine",
"town": "Bethlehem",
"geo": {
"level": "town",
"pairs": "31.92157 35.203285",
"type": "point"
}
},
"partner_id": 289,
"posted_date": "2015-09-04T06:10:04Z",
"planned_expiration_date": "2015-10-04T06:10:04Z",
"loan_amount": 3000,
"borrower_count": 1,
"lender_count": 2,
"bonus_credit_eligibility": false,
"tags": [
{
"name": "user_favorite"
}
]
},
{
"id": 941929,
"name": "Silvia Yesenia",
"description": {
"languages": [
"es",
"en"
]
},
"status": "fundraising",
"funded_amount": 0,
"basket_amount": 0,
"image": {
"id": 1969848,
"template_id": 1
},
"activity": "Retail",
"sector": "Retail",
"themes": [
"Conflict Zones"
],
"use": " to buy vegetables, legumes, staple grains and meat, amongst other items, to offer a better service to her customers",
"location": {
"country_code": "SV",
"country": "El Salvador",
"geo": {
"level": "country",
"pairs": "13.833333 -88.916667",
"type": "point"
}
},
"partner_id": 81,
"posted_date": "2015-09-04T06:10:03Z",
"planned_expiration_date": "2015-10-04T06:10:03Z",
"loan_amount": 500,
"borrower_count": 1,
"lender_count": 0,
"bonus_credit_eligibility": true,
"tags": []
}
]
}
Well the loans array is in the top-level JSON object, so:
NSArray *loans = jsonObject[#"loans"];
for (NSDictionary *loan in loans) {
NSNumber *ident = loan[#"id"];
NSString *name = loan[#"name"];
NSDictionary *description = loan[#"description"];
NSDictionary *location = loan[#"location"];
NSString *country = location[#"country"];
// etc.
}
NSData *allCourseData=[[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:#"http://api.kivaws.org/v1/loans/search.json?status=fundraising"]];
NSError *error;
NSMutableDictionary *JsonObject = [NSJSONSerialization
JSONObjectWithData:allCourseData options:NSJSONReadingMutableContainers
error:&error];
// Get loans array from JsonObject
NSArray *loanJsonObject = JsonObject[#"loans"];
// Create a new loans array for store the new items
NSMutableArray *newLoans = [NSMutableArray array];
// Loop loanJsonObject to get items and create new ones
// for then store them in the new loans array
for (NSDictionary *loan in loanJsonObject) {
NSDictionary *newLoan = #{
#"name": loan[#"name"],
#"status": loan[#"status"],
#"sector": loan[#"sector"],
#"languages": loan[#"description"][#"languages"],
#"location": #{
#"country": loan[#"location"][#"country"],
#"geo": #{
#"pairs": loan[#"location"][#"geo"][#"pairs"]
}
}
};
[newLoans addObject:newLoan];
}
// the new loans
NSLog(#"newLoans: %#", newLoans);
well your loans object is an array of dictionaries.
By [JsonObject objectForKey:#"loans"] you are getting an array.
then you need to iterate for desired result.
NSArray *arrloans = [JsonObject objectForKey:#"loans"];
for (NSDictionary *dicloans in arrloans) {
NSString *name = [JsonObject objectForKey:#"name"];
NSString *countryCode = [[JsonObject objectForKey:#"location"]objectForKey:#"country_code"]; }