Add new non existing column in every document of collection - mongodb-query

I am adding the new column in an existing document
My Existing Document format is:
{
"_id": "5a6026e29cbcdc48083dae1a",
"data": {
"formList": [
{
"IdentificationDetails": [
{
"Status": "Data Entry Completed",
"Form_Id": 1,
"Interviewer_Name": "NAGARAJ.P",
"Group_Id": 9,
"Study_Id": "1",
"Study_Name": "INDIAB",
"Created_Emp_Id": "1",
"Form_Name": "Food Frequency Questionnarie",
"Visit_No": "1",
"Volunteer_Id": "R270116",
"Interview_Date": "2009-10-10T00:00:00Z",
"Volunteer_Name": "RAJENDRA PAWAR"
}
]
},
{
"VFoodDetails": [
{
"Portion_Size": 15,
"Serving_Size": "0",
"Food_Id": 737,
"Value": "0",
"Portion_Tool": 18,
"Volunteer_Id": "R270116",
"Meal_Session": 121,
"Frequency_Serving": "Never"
},
{
"Portion_Size": 168,
"Serving_Size": "0",
"Food_Id": 740,
"Value": "0",
"Portion_Tool": 177,
"Volunteer_Id": "R270116",
"Meal_Session": 121,
"Frequency_Serving": "Never"
}
]
}
]
}
}
I need to add the new column Group_Description in the object of an 'IdentificationDetails' Array.
My Required Json Document is :
{
"_id": "5a6026e29cbcdc48083dae1a",
"data": {
"formList": [
{
"IdentificationDetails": [
{
"Status": "Data Entry Completed",
"Form_Id": 1,
"Interviewer_Name": "NAGARAJ.P",
"Group_Id": 9,
"Study_Id": "1",
"Study_Name": "INDIAB",
"Created_Emp_Id": "1",
"Form_Name": "Food Frequency Questionnarie",
"Visit_No": "1",
"Volunteer_Id": "R270116",
"Interview_Date": "2009-10-10T00:00:00Z",
"Volunteer_Name": "RAJENDRA PAWAR",
}
]
},
{
"VFoodDetails": [
{
"Portion_Size": 15,
"Serving_Size": "0",
"Food_Id": 737,
"Value": "0",
"Portion_Tool": 18,
"Volunteer_Id": "R270116",
"Meal_Session": 121,
"Frequency_Serving": "Never"
},
{
"Portion_Size": 168,
"Serving_Size": "0",
"Food_Id": 740,
"Value": "0",
"Portion_Tool": 177,
"Volunteer_Id": "R270116",
"Meal_Session": 121,
"Frequency_Serving": "Never",
"Group_Description": "Urban"
}
]
}
]
}
}
My Update Command which is created the column in the last of the json:
db.FrequencyQuestionForm.update({"data.formList.IdentificationDetails.Group_Id"
:9.0 },{$set : {"Group_Description":"Urban"}},{ multi: true })
{
"_id": "5a6026e29cbcdc48083dae1a",
"data": {
"formList": [
{
"IdentificationDetails": [
{
"Status": "Data Entry Completed",
"Form_Id": 1,
"Interviewer_Name": "NAGARAJ.P",
"Group_Id": 9,
"Study_Id": "1",
"Study_Name": "INDIAB",
"Created_Emp_Id": "1",
"Form_Name": "Food Frequency Questionnarie",
"Visit_No": "1",
"Volunteer_Id": "R270116",
"Interview_Date": "2009-10-10T00:00:00Z",
"Volunteer_Name": "RAJENDRA PAWAR",
"Group_Description": "Urban"
}
]
},
{
"VFoodDetails": [
{
"Portion_Size": 15,
"Serving_Size": "0",
"Food_Id": 737,
"Value": "0",
"Portion_Tool": 18,
"Volunteer_Id": "R270116",
"Meal_Session": 121,
"Frequency_Serving": "Never"
},
{
"Portion_Size": 168,
"Serving_Size": "0",
"Food_Id": 740,
"Value": "0",
"Portion_Tool": 177,
"Volunteer_Id": "R270116",
"Meal_Session": 121,
"Frequency_Serving": "Never"
}
]
}
]
},
"Group_Description": "Urban"
}

The command to add the new non-existing column in all mongodb documents in a collection is:
db.FrequencyQuestionForm.update(
{'data.formList.IdentificationDetails.Group_Id': 9 },
{'$set': {'data.formList.0.IdentificationDetails.0.Group_Description': "abc"}},{ multi: true } );

Related

changing state of kepler.gl on a button click

I am working on kepler.gl . i am trying to add another point on map and change the state of kepler.gl on a button click . I mean when i click the button another point is mapped on keppler.gl map . wright now i am having 4 point on the kepler.gl map and that's working fine ... here is the code of 4 point on the map
import React, { useState } from "react";
import keplerGlReducer, {mapStateUpdaters} from "kepler.gl/reducers";
import { createStore, combineReducers, applyMiddleware } from "redux";
import { taskMiddleware } from "react-palm/tasks";
import { Provider, useDispatch } from "react-redux";
import KeplerGl from "kepler.gl";
import { addDataToMap } from "kepler.gl/actions";
import useSwr from "swr";
import {csv} from 'd3';
import datajson from './Data/data.json'
const reducers = combineReducers({
keplerGl: keplerGlReducer,
});
const store = createStore(reducers, {}, applyMiddleware(taskMiddleware));
export default function App() {
return (
<Provider store={store}>
<Map />
</Provider>
);
}
function Map() {
const dispatch = useDispatch();
const data=datajson;
React.useEffect(() => {
if (data) {
dispatch(
addDataToMap({
datasets: {
info: {
label: "COVID-19",
id: "covid19"
},
data
},
option: {
centerMap: true,
readOnly: false
},
config: {}
})
);
}
}, [dispatch, data]);
return (
// <button onClick ={this.handledata} >changedata</button>
<KeplerGl
id="covid"
mapboxApiAccessToken="pk.eyJ1IjoiYWxpcmF6YTcwNSIsImEiOiJjazh5d2hjb3AwOHBqM2VsY21wOHo5eXprIn0.9G5CE4KqfbvU9HQ6WBuo3w"
width={window.innerWidth}
height={window.innerHeight}
/>
);
}}
my data.jason file look like this ....
[
{
"id": 139010,
"state": 4,
"subState": 0,
"paid": 1,
"stateReason": "Trip finished by user",
"id_turistic": 5,
"priceFinal": 60,
"consumedFreeMinutes": 0,
"id_user": 4627,
"id_vehicle": 245,
"from": "nan",
"to": "Sol",
"batt_diff": -8,
"duracion": 412,
"fecha": "2018-09-01",
"start30": "2018-09-01 08:00:00",
"end30": "2018-09-01 08:00:00",
"distancia": 2,
"latitude": 40.0,
"longitude": -4.0
},
{
"id": 138888,
"state": 4,
"subState": 0,
"paid": 1,
"stateReason": "Trip finished by user",
"id_turistic": 5,
"priceFinal": 100,
"consumedFreeMinutes": 0,
"id_user": 4627,
"id_vehicle": 245,
"from": "Universidad",
"to": "Embajadores",
"batt_diff": -4,
"duracion": 646,
"fecha": "2018-09-01",
"start30": "2018-09-01 00:00:00",
"end30": "2018-09-01 00:00:00",
"distancia": 4,
"latitude": "40.0",
"longitude": "-4.0"
},
{
"id": 138878,
"state": 4,
"subState": 0,
"paid": 1,
"stateReason": "Trip finished by user",
"id_turistic": 5,
"priceFinal": 110,
"consumedFreeMinutes": 0,
"id_user": 10244,
"id_vehicle": 173,
"from": "Vallehermoso",
"to": "Cuatro Caminos",
"batt_diff": -7,
"duracion": 682,
"fecha": "2018-09-01",
"start30": "2018-09-01 00:00:00",
"end30": "2018-09-01 00:00:00",
"distancia": 3,
"latitude": "40.0",
"longitude": "-4.0"
},
{
"id": 138941,
"state": 4,
"subState": 0,
"paid": 0,
"stateReason": "Trip finished by user",
"id_turistic": 5,
"priceFinal": 170,
"consumedFreeMinutes": 0,
"id_user": 12133,
"id_vehicle": 207,
"from": "Justicia",
"to": "Prosperidad",
"batt_diff": -7,
"duracion": 1031,
"fecha": "2018-09-01",
"start30": "2018-09-01 02:00:00",
"end30": "2018-09-01 02:00:00",
"distancia": 5,
"latitude": "40.0",
"longitude": "-4.0"
}
]
now i want to add another point on a click of button ? like for example i want to add that point on a button click
{
"fields": [
{
"name": "id",
"format": "",
"type": "integer"
},
{
"name": "state",
"format": "",
"type": "integer"
},
{
"name": "substate",
"format": "",
"type": "integer"
},
{
"name": "paid",
"format": "",
"type": "integer"
},
{
"name": "stateReason",
"format": "",
"type": "string"
},
{
"name": "id_turistic",
"format": "",
"type": "integer"
},
{
"name": "priceFinal",
"format": "",
"type": "integer"
},
{
"name": "consumedFreeMinutes",
"format": "",
"type": "integer"
},
{
"name": "consumed",
"format": "",
"type": "integer"
},
{
"name": "id_user",
"format": "",
"type": "integer"
},
{
"name": "id_vehicle",
"format": "",
"type": "integer"
},
{
"name": "from",
"format": "",
"type": "string"
},
{
"name": "to",
"format": "",
"type": "string"
},
{
"name": "batt_diff",
"format": "",
"type": "string"
},
{
"name": "duracion",
"format": "",
"type": "string"
},
{
"name": "fecha",
"format": "YYYY-M-D H:m:s",
"type": "timestamp"
},
{
"name": "start30",
"format": "YYYY-M-D H:m:s",
"type": "timestamp"
},
{
"name": "end30",
"format": "YYYY-M-D H:m:s",
"type": "timestamp"
},
{
"name": "distancia",
"format": "",
"type": "integer"
},
{
"name": "latitude",
"format": "",
"type": "real"
},
{
"name": "longitude",
"format": "",
"type": "real"
},
{
"name": "lo",
"format": "",
"type": "real"
}
],
"rows": [
[
139010,
4,
0,
1,
"Trip finished by user",
5,
60,
0,
4627,
245,
"nan",
"Sol",
-8,
412,
"2018-09-01",
"2018-09-01 08:00:00",
"2018-09-01 08:00:00",
2,
40.0,
-12,
40.0
],
[
138888,
4,
0,
1,
"Trip finished by user",
5,
100,
0,
4627,
245,
"Universidad",
"Embajadores",
-4,
646,
"2018-09-01",
"2018-09-01 08:00:00",
"2018-09-01 08:00:00",
4,
40.0,
0,
40.0
],
[
138878,
4,
0,
1,
"Trip finished by user",
5,
110,
0,
10244,
173,
"Vallehermoso",
"Cuatro Caminos",
-7,
682,
"2018-09-01",
"2018-09-01 08:00:00",
"2018-09-01 08:00:00",
3,
40.0,
-8.0,
40.0
],
[
138941,
4,
0,
0,
"Trip finished by user",
5,
170,
0,
12133,
207,
"Justicia",
"Prosperidad",
-7,
1031,
"2018-09-01",
"2018-09-01 08:00:00",
"2018-09-01 08:00:00",
5,
40.0,
-4.0,
40.0
]
]
}
how can i do this can anyone help me for this? i already tried mapstateupdataer function but not been able to get desired results ?
I think you have not defined the button event handler. First, you need to define it and then you can dispatch the action with the new data.
For example, if you have a button with an event handler inside your render() method.
<Button onClick={addData}>Add Data</Button>
Update: To append existing data-set on the map. You have to import a new action from kepler/actions and dispatch it.
import {updateMap} from 'kepler.gl/actions'
const addData= () => {
const data = {latitude: 37.75043, longitude: -122.34679, width: 800, height: 1200};
dispatch(updateMap(data));
};
You have to assign your data (the array of objects in your question) to a variable. Let's call it as sampleData. And This is how your replaceData handler should be like:
const addData= () => {
const sampleData = ['your-new-data-set'];
const config = this.getMapConfig();
dispatch(
addDataToMap({
datasets: {
info: {
label: "COVID-19",
id: "covid19"
},
sampleData
},
option: {
centerMap: true,
readOnly: false
},
config: {}
})
);
};

Decode bitcoin transaction vin address

I'm building a graph of blockchain transactions and have a problem to extract source address for a transaction (output addresses are easy,bundled in the getrawtransaction result).
for example this transaction https://www.blockchain.com/btc/tx/8d787db12e04630a10191772f068fae43d30fbb93e6198e7efa636ce03f16222?show_adv=true
the getrawtransaction has an output of
{
"result": {
"txid": "8d787db12e04630a10191772f068fae43d30fbb93e6198e7efa636ce03f16222",
"hash": "7a0a667bf96d65a11eeab8ec17e232c5afdbe724b6e5e60697790bde3037c2c8",
"version": 2,
"size": 248,
"vsize": 166,
"weight": 662,
"locktime": 597359,
"vin": [
{
"txid": "2a1dda8fb17cdcefb26a377492aff6076bd03a93f742d595df1d0ff4951a4305",
"vout": 0,
"scriptSig": {
"asm": "00140d9cad5ccd91bf6ed56ec6bcb7762ec52ecb7b8d",
"hex": "1600140d9cad5ccd91bf6ed56ec6bcb7762ec52ecb7b8d"
},
"txinwitness": [
"3045022100f2900ede33aab8838464cfb127a962960c29cd97ba62e830c69a38621514d2980220706aa5c28d6e1a134f74b99e6280b357dc1f20ae00f4fcca12ab4ccfab5ceac701",
"033b18a261c30edaf859dc523700f3a6085a413ab51b4f63ca84d26073e8e7c709"
],
"sequence": 4294967294
}
],
"vout": [
{
"value": 0.16957303,
"n": 0,
"scriptPubKey": {
"asm": "OP_HASH160 d45c146bdb6ad9c61f3300341e2524e8e64394ac OP_EQUAL",
"hex": "a914d45c146bdb6ad9c61f3300341e2524e8e64394ac87",
"reqSigs": 1,
"type": "scripthash",
"addresses": [
"3M3sV2VBqPXzZHkbdBXo9dMpEw7xxHCFow"
]
}
},
{
"value": 0.07866618,
"n": 1,
"scriptPubKey": {
"asm": "OP_HASH160 69f37417a9fb77744ec258ac2ff22e99266ac354 OP_EQUAL",
"hex": "a91469f37417a9fb77744ec258ac2ff22e99266ac35487",
"reqSigs": 1,
"type": "scripthash",
"addresses": [
"3BMEX8XxUxyEKfRDAJmSMhyd3Y7QWh7PQV"
]
}
}
],
"hex": "0200000000010105431a95f40f1ddf95d542f7933ad06b07f6af9274376ab2efdc7cb18fda1d2a00000000171600140d9cad5ccd91bf6ed56ec6bcb7762ec52ecb7b8dfeffffff0277bf02010000000017a914d45c146bdb6ad9c61f3300341e2524e8e64394ac87fa0878000000000017a91469f37417a9fb77744ec258ac2ff22e99266ac3548702483045022100f2900ede33aab8838464cfb127a962960c29cd97ba62e830c69a38621514d2980220706aa5c28d6e1a134f74b99e6280b357dc1f20ae00f4fcca12ab4ccfab5ceac70121033b18a261c30edaf859dc523700f3a6085a413ab51b4f63ca84d26073e8e7c7096f1d0900",
"blockhash": "00000000000000000002726a175241b0f200c561daf30c668d8652cf3b949343",
"confirmations": 18,
"time": 1569914555,
"blocktime": 1569914555
},
"error": null,
"id": null
}
the source address per blockchain explorer is 36UuEDoDQX5JppSVnpaccV5DCKiquRyPxB. Was not able to derive it from any of the vin fields.
You can decode scriptSig to get the address.
There is a RPC call in bitcoin core that can help you achieve this: decodescript.

Parsing Twitter Information with jq ("text": null)

I am trying to do some Twitter-analysis via Twurl and extract some information via jq.
I firstly get some tweets via twurl with the command
twurl /1.1/users/search.json?q=judo
Then i used the following line to structure the outpot with jq:
twurl /1.1/users/search.json?q=judo | jq
i get something like this:
[
{
"id": 173752759,
"id_str": "173752759",
"name": "#JudoWorlds πŸ₯‹",
"screen_name": "Judo",
"location": "Worldwide",
"description": "The Official Twitter Account of the International Judo Federation πŸ₯‹",
"url": "https:.....",
"entities": {
"url": {
"urls": [
{
"url": "https://......",
"expanded_url": "https://www.ijf.org/news/show/5-must-see-preliminary-round-clashes-2",
"display_url": "ijf.org/news/show/5-mu…",
"indices": [
0,
23
]
}
]
},
"description": {
"urls": []
}
},
"protected": false,
"followers_count": 59854,
"friends_count": 847,
"listed_count": 529,
"created_at": "Mon Aug 02 07:55:15 +0000 2010",
"favourites_count": 7074,
"utc_offset": null,
"time_zone": null,
"geo_enabled": true,
"verified": true,
"statuses_count": 16532,
"lang": null,
"status": {
"created_at": "Fri Aug 30 08:27:10 +0000 2019",
"id": 1167353053282013200,
"id_str": "1167353053282013184",
"text": "#JudoWorlds The Alternative Promo \n\n#NeilAdamsJudo https://.....",
"truncated": false,
"entities": {
"hashtags": [
{
"text": "JudoWorlds",
"indices": [
0,
11
]
}
],
"symbols": [],
"user_mentions": [
{
"screen_name": "NeilAdamsJudo",
"name": "Neil Adams MBE",
"id": 40488733,
"id_str": "40488733",
"indices": [
36,
50
]
}
],
"urls": [],
"media": [
{
"id": 1167352899267002400,
"id_str": "1167352899267002369",
"indices": [
51,
74
],
"media_url": "http://pbs.twimg.com/ext_tw_video_thumb/1167352899267002369/pu/img/6yD1r7uaPV7p3y6a.jpg",
"media_url_https": "https://pbs.twimg.com/ext_tw_video_thumb/1167352899267002369/pu/img/6yD1r7uaPV7p3y6a.jpg",
"url": "https://......",
"display_url": "pic.twitter.com/0RlLbKLkN8",
"expanded_url": "https://twitter.com/Judo/status/1167353053282013184/video/1",
"type": "photo",
"sizes": {
"thumb": {
"w": 150,
"h": 150,
"resize": "crop"
},
"medium": {
"w": 1200,
"h": 675,
"resize": "fit"
},
"small": {
"w": 680,
"h": 383,
"resize": "fit"
},
"large": {
"w": 1280,
"h": 720,
"resize": "fit"
}
}
}
]
},
"extended_entities": {
"media": [
{
"id": 1167352899267002400,
"id_str": "1167352899267002369",
"indices": [
51,
74
],
"media_url": "http://pbs.twimg.com/ext_tw_video_thumb/1167352899267002369/pu/img/6yD1r7uaPV7p3y6a.jpg",
"media_url_https": "https://pbs.twimg.com/ext_tw_video_thumb/1167352899267002369/pu/img/6yD1r7uaPV7p3y6a.jpg",
"url": "https://.....",
"display_url": "pic.twitter.com/0RlLbKLkN8",
"expanded_url": "https://twitter.com/Judo/status/1167353053282013184/video/1",
"type": "video",
"sizes": {
"thumb": {
"w": 150,
"h": 150,
"resize": "crop"
},
"medium": {
"w": 1200,
"h": 675,
"resize": "fit"
},
"small": {
"w": 680,
"h": 383,
"resize": "fit"
},
"large": {
"w": 1280,
"h": 720,
"resize": "fit"
}
},
"video_info": {
"aspect_ratio": [
16,
9
],
"duration_millis": 48800,
"variants": [
{
"bitrate": 256000,
"content_type": "video/mp4",
"url": "https://video.twimg.com/ext_tw_video/1167352899267002369/pu/vid/480x270/v4nkTg6qs9rpLq8M.mp4?tag=10"
},
{
"content_type": "application/x-mpegURL",
"url": "https://video.twimg.com/ext_tw_video/1167352899267002369/pu/pl/SQN57QxQFYcKWV7l.m3u8?tag=10"
},
{
"bitrate": 2176000,
"content_type": "video/mp4",
"url": "https://video.twimg.com/ext_tw_video/1167352899267002369/pu/vid/1280x720/8cyNocB_8CRjwVCI.mp4?tag=10"
},
{
"bitrate": 832000,
"content_type": "video/mp4",
"url": "https://video.twimg.com/ext_tw_video/1167352899267002369/pu/vid/640x360/uy2U7D_AEmbLdqEK.mp4?tag=10"
}
]
},
"additional_media_info": {
"monetizable": false
}
}
]
},
"source": "Twitter for Android",
"in_reply_to_status_id": null,
"in_reply_to_status_id_str": null,
"in_reply_to_user_id": null,
"in_reply_to_user_id_str": null,
"in_reply_to_screen_name": null,
"geo": null,
"coordinates": null,
"place": null,
"contributors": null,
"is_quote_status": false,
"retweet_count": 4,
"favorite_count": 17,
"favorited": false,
"retweeted": false,
"possibly_sensitive": false,
"lang": "en"
},
"contributors_enabled": false,
"is_translator": false,
"is_translation_enabled": false,
"profile_background_color": "0099CC",
"profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/bg.png",
"profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme1/bg.png",
"profile_background_tile": false,
"profile_image_url": "http://pbs.twimg.com/profile_images/1057928008797970433/O3l2sKj0_normal.jpg",
"profile_image_url_https": "https://pbs.twimg.com/profile_images/1057928008797970433/O3l2sKj0_normal.jpg",
"profile_banner_url": "https://pbs.twimg.com/profile_banners/173752759/1565853008",
"profile_link_color": "0C3C42",
"profile_sidebar_border_color": "8F320A",
"profile_sidebar_fill_color": "F2CF41",
"profile_text_color": "000000",
"profile_use_background_image": true,
"has_extended_profile": false,
"default_profile": false,
"default_profile_image": false,
"following": false,
"follow_request_sent": false,
"notifications": false,
"translator_type": "none"
},
Because i am only interested in certain informations i tried to get the name and the text of the tweet with the following command:
twurl /1.1/users/search.json?q=judo | jq ".[] | { name: .name, text: .text }"
and i get this:
{
"name": "#JudoWorlds πŸ₯‹",
"text": null
}
{
"name": "#WeAreGBJudo",
"text": null
}
{
"name": "CBJ",
"text": null
}
{
"name": "Santos Futebol Clube",
"text": null
}
{
"name": "Marius Vizer",
"text": null
}
{
"name": "FF Judo",
"text": null
}
{
"name": "Santos FC πŸ‡Ί πŸ‡Έ πŸ‡¬ πŸ‡§ ",
"text": null
}
{
"name": "USA Judo",
"text": null
}
{
"name": "ε…¨ζ—₯ζœ¬ζŸ”ι“ι€£η›Ÿ -ゴジラジャパン-",
"text": null
}
{
"name": "Vila Belmiro",
"text": null
}
{
"name": "Deutscher Judo-Bund",
"text": null
}
{
"name": "Bruno Secco",
"text": null
}
{
"name": "Bobby Judo",
"text": null
}
{
"name": "African Judo Union",
"text": null
}
{
"name": "JudoInside.com",
"text": null
}
{
"name": "For competitive judo",
"text": null
}
{
"name": "Judo Canada",
"text": null
}
{
"name": "Neil Adams MBE",
"text": null
}
{
"name": "Sophie Cox",
"text": null
}
{
"name": "Galatasaray Judo",
"text": null
}
Why is this and how can i fix it?
I tried other commands like :
twurl /1.1/search/tweets.json?q=afd | jq ".[] | { name: .name, text: .text }"
but got the error
jq: error (at <stdin>:0): Cannot index array with string "name"
If you need nested 'text' value from 'status' field you should use:
.[] | { name: .name, text: .status.text }
Or shorter version:
.[] | { name, text: .status.text }

Highcharts-vue: Stacked Columns with Drilldown

I'm trying to replicate this chart http://jsfiddle.net/edzk8Loe/ using vue js.
To be honest, I'm learning vuejs and so I'm trying to replicate already ready projects to get confident quickly.
The issue I'm facing at the moment I guess is a logic one. The functions have to create new series as drilldown when click on a column, seams not triggered at all. I'm not getting any error in the console and I'm
Not having yet a totally clear idea about the structure, I think I'm messing up the code. Hereunder you'll find the code I'm using in VUE.
<template>
<div class="chartElem">
<div class="row">
<highcharts class="chart" :constructor-type="'chart'" :options="chartOptions"></highcharts>
</div>
</div>
</template>
<script>
import HighchartsVue from "highcharts-vue";
import Highcharts from "highcharts";
import dataModule from "highcharts/modules/data";
import drilldown from "highcharts/modules/drilldown";
drilldown( Highcharts );
dataModule( Highcharts );
let drilldownChart, drilldownEvent, drilldownLevel = 0;
const chartOptions = {
chart: {
"type": "column",
},
credits: {
"enabled": false
},
plotOptions: {
column: {
stacking: "normal",
events: {
click: function ( event ) {
return false;
}
}
},
"series": {
"borderWidth": 0,
"dataLabels": {
"enabled": true,
"style": {
"textShadow": false,
"fontSize": "10px"
}
}
}
},
"legend": {
"enabled": false,
},
"yAxis": {
"stackLabels": {
"enabled": false,
"style": {
"fontWeight": "bold",
"color": "gray"
}
}
},
"title": {
"text": "Stacked Column Drilldown Chart",
"fontWeight": "bold"
},
"xAxis": {
"title": {},
"type": "category"
},
"yAxis": [ {
"title": {
"text": "Number of Students"
},
"min": 0,
"allowDecimals": false
} ],
"series": [ {
"name": "Outstanding",
"color": "rgb(102, 168, 255)",
"data": [ {
"name": "English",
"y": 0,
"parentCategoryHierarchyId": "0",
"graphParentId": "105"
}, {
"name": "Social Science",
"y": 1,
"parentCategoryHierarchyId": "0",
"graphParentId": "119",
"drilldown": true
}, {
"name": "Science",
"y": 0,
"parentCategoryHierarchyId": "0",
"graphParentId": "126"
}, {
"name": "Maths",
"y": 0,
"parentCategoryHierarchyId": "0",
"graphParentId": "139"
}, {
"name": "Hindi",
"y": 0,
"parentCategoryHierarchyId": "0",
"graphParentId": "146"
} ]
}, {
type: 'column',
"name": "Very Good",
"color": "rgb(128, 183, 255)",
"data": [ {
"name": "English",
"y": 0,
"parentCategoryHierarchyId": "0",
"graphParentId": "105"
}, {
"name": "Social Science",
"y": 0,
"parentCategoryHierarchyId": "0",
"graphParentId": "119",
"drilldown": true
}, {
"name": "Science",
"y": 0,
"parentCategoryHierarchyId": "0",
"graphParentId": "126"
}, {
"name": "Maths",
"y": 0,
"parentCategoryHierarchyId": "0",
"graphParentId": "139"
}, {
"name": "Hindi",
"y": 0,
"parentCategoryHierarchyId": "0",
"graphParentId": "146"
} ]
}, {
type: 'column',
"name": "Satisfactory",
"color": "rgb(179, 212, 255)",
"data": [ {
"name": "English",
"y": 0,
"parentCategoryHierarchyId": "0",
"graphParentId": "105"
}, {
"name": "Social Science",
"y": 1,
"parentCategoryHierarchyId": "0",
"graphParentId": "119",
"drilldown": true
}, {
"name": "Science",
"y": 0,
"parentCategoryHierarchyId": "0",
"graphParentId": "126"
}, {
"name": "Maths",
"y": 0,
"parentCategoryHierarchyId": "0",
"graphParentId": "139"
}, {
"name": "Hindi",
"y": 0,
"parentCategoryHierarchyId": "0",
"graphParentId": "146"
} ]
}, {
type: 'column',
"name": "Needs Improvement",
"color": "rgb(204, 226, 255)",
"data": [ {
"name": "English",
"y": 0,
"parentCategoryHierarchyId": "0",
"graphParentId": "105"
}, {
"name": "Social Science",
"y": 0,
"parentCategoryHierarchyId": "0",
"graphParentId": "119",
"drilldown": true
}, {
"name": "Science",
"y": 0,
"parentCategoryHierarchyId": "0",
"graphParentId": "126"
}, {
"name": "Maths",
"y": 0,
"parentCategoryHierarchyId": "0",
"graphParentId": "139"
}, {
"name": "Hindi",
"y": 0,
"parentCategoryHierarchyId": "0",
"graphParentId": "146"
} ]
}, {
type: 'column',
"name": "Not Performing",
"color": "rgb(230, 242, 255)",
"data": [ {
"name": "English",
"y": 0,
"parentCategoryHierarchyId": "0",
"graphParentId": "105"
}, {
"name": "Social Science",
"y": 0,
"parentCategoryHierarchyId": "0",
"graphParentId": "119",
"drilldown": true
}, {
"name": "Science",
"y": 0,
"parentCategoryHierarchyId": "0",
"graphParentId": "126"
}, {
"name": "Maths",
"y": 0,
"parentCategoryHierarchyId": "0",
"graphParentId": "139"
}, {
"name": "Hindi",
"y": 0,
"parentCategoryHierarchyId": "0",
"graphParentId": "146"
} ]
} ]
};
export default {
data: () => ( {
chartOptions,
drilldownChart,
drilldownEvent,
drilldownLevel
} ),
methods: {},
computed:{
drilldown: function ( e ) {
if ( !e.seriesOptions ) {
updateGraph( true, this, e );
}
},
drillup: function ( e ) {
if ( !e.seriesOptions.flag ) {
drilldownLevel = e.seriesOptions._levelNumber;
updateGraph( false );
}
}
},
mounted() {
function updateGraph( isDrilldown, chart, e ) {
if ( isDrilldown ) {
drilldownLevel++;
drilldownChart = chart;
drilldownEvent = e;
if ( drilldownLevel === 1 ) {
var drilldowns = {
'Social Science': {
name: 'Outstanding',
color: 'rgb(102, 168, 255)',
data: [ {
name: 'Geography',
y: 7,
drilldown: true
}, {
name: 'History',
y: 4
}, {
name: 'Civics',
y: 9
} ]
}
},
drilldowns2 = {
'Social Science': {
name: 'Very Good',
color: 'rgb(128, 183, 255)',
data: [ {
name: 'Geography',
y: 4,
drilldown: true
}, {
name: 'History',
y: 8
}, {
name: 'Civics',
y: 2
} ],
},
},
drilldowns3 = {
'Social Science': {
name: 'Satisfactory',
color: 'rgb(179, 212, 255)',
data: [ {
name: 'Geography',
y: 4,
drilldown: true
}, {
name: 'History',
y: 7
}, {
name: 'Civics',
y: 1
} ],
}
},
drilldowns4 = {
'Social Science': {
name: 'Needs Improvement',
color: 'rgb(204, 226, 255)',
data: [ {
name: 'Geography',
y: 2,
drilldown: true
}, {
name: 'History',
y: 7
}, {
name: 'Civics',
y: 2
} ]
}
},
drilldowns5 = {
'Social Science': {
name: 'Not Performing',
color: 'rgb(230, 242, 255)',
data: [ {
name: 'Geography',
y: 6,
drilldown: true
}, {
name: 'History',
y: 3
}, {
name: 'Civics',
y: 0
} ],
}
},
series = drilldowns[ e.point.name ],
series2 = drilldowns2[ e.point.name ],
series3 = drilldowns3[ e.point.name ],
series4 = drilldowns4[ e.point.name ],
series5 = drilldowns5[ e.point.name ];
chart.addSingleSeriesAsDrilldown( e.point, series );
chart.addSingleSeriesAsDrilldown( e.point, series2 );
chart.addSingleSeriesAsDrilldown( e.point, series3 );
chart.addSingleSeriesAsDrilldown( e.point, series4 );
chart.addSingleSeriesAsDrilldown( e.point, series5 );
chart.applyDrilldown();
} else if ( drilldownLevel === 2 ) {
var drilldown1 = {
"Geography": {
"name": "Yes",
stacking: 'percent',
color: 'red',
"data": [ {
"name": "Q1",
"y": 1
}, {
"name": "Q2",
"y": 2
}, {
"name": "Q3",
"y": 3
}, {
"name": "Q4",
"y": 4
} ]
}
};
var drilldown2 = {
"Geography": {
"name": "No",
stacking: 'percent',
color: 'green',
"data": [ {
"name": "Q1",
"y": 1
}, {
"name": "Q2",
"y": 2
}, {
"name": "Q3",
"y": 3
}, {
"name": "Q4",
"y": 4
} ]
}
};
var drilldown3 = {
"exampleDrilldown": {
type: 'line',
"name": "Example",
color: 'black',
"data": [ {
"name": "Q1",
"y": 10
}, {
"name": "Q2",
"y": 20
}, {
"name": "Q3",
"y": 30
}, {
"name": "Q4",
"y": 40
} ]
}
}
chart.addSingleSeriesAsDrilldown( e.point, drilldown1[ e.point.name ] );
chart.addSingleSeriesAsDrilldown( e.point, drilldown2[ e.point.name ] );
chart.addSingleSeriesAsDrilldown( e.point, drilldown3[ 'exampleDrilldown' ] );
console.log( e );
chart.applyDrilldown();
}
}
}
}
}
</script>
I'm not looking for someone is doing the task instead of me, I won't learn anything. Ideas and tips are super welcomed.
Cheers
You've made several simple mistakes in your code.
1) Add updateGraph function to chart methods - that way you can invoke this method in drilldown callback
2) Save chart component reference in the chart object to be able to use updateGraph method from drilldown callback function. You can make it using mounted() hook:
mounted() {
this.$children[0].chart.vueRef = this;
}
3) Data should be a function that returns an object with properties:
data() {
return {
chartOptions,
drilldownChart,
drilldownEvent,
drilldownLevel
}
}
4) Add drilldown and drillup callbacks to chart.events object. There you can invoke updateGraph method from the chart component reference saved in mounted hook:
chart: {
"type": "column",
events: {
drilldown: function(e) {
if (!e.seriesOptions) {
this.vueRef.updateGraph(true, this, e);
}
},
drillup: function(e) {
if (!e.seriesOptions.flag) {
this.vueRef.drilldownLevel = e.seriesOptions._levelNumber;
this.vueRef.updateGraph(false);
}
}
}
}
Demo:
https://codesandbox.io/s/2w513lwpw0

JSON Objective-c - Objects and Arrays Combination

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"]; }