I'm trying to map a nested JSON to the model object, the problem is when it returns null, it will break all the code, I want to check if null do something but not break the app.
THE JSON FILE:
[
{
"id": 53,
"date": "2018-12-28T08:51:11",
"title": {
"rendered": "this is for featured"
},
"content": {
"rendered": "\n<p><g class=\"gr_ gr_3 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling\" id=\"3\" data-gr-id=\"3\">sdafkj</g> <g class=\"gr_ gr_10 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace\" id=\"10\" data-gr-id=\"10\">kj</g> <g class=\"gr_ gr_16 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace\" id=\"16\" data-gr-id=\"16\">asd</g> <g class=\"gr_ gr_18 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling\" id=\"18\" data-gr-id=\"18\">kadjsfk</g> kljadfklj sd</p>\n",
"protected": false
},
"excerpt": {
"rendered": "<p>sdafkj kj asd kadjsfk kljadfklj sd</p>\n",
"protected": false
},
"author": 1,
"featured_media": 54,
"_links": {
"self": [
{
"href": "https://client.kurd.app/wp-json/wp/v2/posts/53"
}
],
},
"_embedded": {
"author": [
{
"id": 1,
"name": "hooshyar",
}
],
"wp:featuredmedia": [
{
"id": 54,
"source_url": "https://client.kurd.app/wp-content/uploads/2018/12/icannotknow_22_12_2018_18_48_11_430.jpg",
}
]
}
]
CODE FOR MAPPING TO OBJECT:
featuredMediaUrl = map ["_embedded"]["wp:featuredmedia"][0]["source_url"];
The method 'map' was called on null. Receiver: null [0] which sometimes returns null ;