Swift Parse JSON Error : No value associated with key CodingKeys(stringValue: "_sourceSwift : The data couldn’t be read because it isn’t in the correct formatWhy can't Python parse this JSON data?Parse JSON in JavaScript?Parse nested JSON in Swift 4.1I am try to fetch the data from sql server through WCF serviceJSON Parsing Swift 4Parsing the JSON iOS-Swiftswift parsing json No value associated with key CodingKeys(stringValue: “id”, intValue: nil) (“id”)swift parse json error “No value associated with key CodingKeys(stringValue: ”id“, intValue: nil) (”id“).”NSObject Decodable same valueNot able to parse data using Codable and Alamofire 3.0

How do I tell my boss that I'm quitting in 15 days (a colleague left this week)

Origin of pigs as a species

How to make money from a browser who sees 5 seconds into the future of any web page?

Is there anyway, I can have two passwords for my wi-fi

Can I run 125kHz RF circuit on a breadboard?

Did I make a mistake by ccing email to boss to others?

Sound waves in different octaves

Deciphering cause of death?

Grepping string, but include all non-blank lines following each grep match

Make a Bowl of Alphabet Soup

Pre-Employment Background Check With Consent For Future Checks

How to understand "he realized a split second too late was also a mistake"

Identifying "long and narrow" polygons in with PostGIS

Do you waste sorcery points if you try to apply metamagic to a spell from a scroll but fail to cast it?

How do I prevent inappropriate ads from appearing in my game?

Difference between shutdown options

How to get directions in deep space?

Proving an identity involving cross products and coplanar vectors

What does "tick" mean in this sentence?

What is this high flying aircraft over Pennsylvania?

Isometric embedding of a genus g surface

Why does the Persian emissary display a string of crowned skulls?

How many people need to be born every 8 years to sustain population?

Are inadvertent environmental catastrophes also examples of natural selection?



Swift Parse JSON Error : No value associated with key CodingKeys(stringValue: "_source


Swift : The data couldn’t be read because it isn’t in the correct formatWhy can't Python parse this JSON data?Parse JSON in JavaScript?Parse nested JSON in Swift 4.1I am try to fetch the data from sql server through WCF serviceJSON Parsing Swift 4Parsing the JSON iOS-Swiftswift parsing json No value associated with key CodingKeys(stringValue: “id”, intValue: nil) (“id”)swift parse json error “No value associated with key CodingKeys(stringValue: ”id“, intValue: nil) (”id“).”NSObject Decodable same valueNot able to parse data using Codable and Alamofire 3.0













-2















I am attempting to parse the following json data:



enter image description here



Below is my struct:



struct Album: Decodable 
var source: [Sourcet]
enum CodingKeys: String, CodingKey
case source = "_source"



struct Sourcet: Decodable
var nome, endereco, uf, cidade, bairro: String



let response = try JSONDecoder().decode(Album.self, from: data)



I continue getting the error:




keyNotFound(CodingKeys(stringValue: "_source", intValue: nil),
Swift.DecodingError.Context(codingPath: [], debugDescription: "No
value associated with key CodingKeys(stringValue: "_source",
intValue: nil) ("_source").", underlyingError: nil))




Is this due to the json information being an array?.How would I be able to parse this information?










share|improve this question






















  • Possible duplicate of Swift : The data couldn’t be read because it isn’t in the correct format

    – staticVoidMan
    Mar 8 at 11:19















-2















I am attempting to parse the following json data:



enter image description here



Below is my struct:



struct Album: Decodable 
var source: [Sourcet]
enum CodingKeys: String, CodingKey
case source = "_source"



struct Sourcet: Decodable
var nome, endereco, uf, cidade, bairro: String



let response = try JSONDecoder().decode(Album.self, from: data)



I continue getting the error:




keyNotFound(CodingKeys(stringValue: "_source", intValue: nil),
Swift.DecodingError.Context(codingPath: [], debugDescription: "No
value associated with key CodingKeys(stringValue: "_source",
intValue: nil) ("_source").", underlyingError: nil))




Is this due to the json information being an array?.How would I be able to parse this information?










share|improve this question






















  • Possible duplicate of Swift : The data couldn’t be read because it isn’t in the correct format

    – staticVoidMan
    Mar 8 at 11:19













-2












-2








-2








I am attempting to parse the following json data:



enter image description here



Below is my struct:



struct Album: Decodable 
var source: [Sourcet]
enum CodingKeys: String, CodingKey
case source = "_source"



struct Sourcet: Decodable
var nome, endereco, uf, cidade, bairro: String



let response = try JSONDecoder().decode(Album.self, from: data)



I continue getting the error:




keyNotFound(CodingKeys(stringValue: "_source", intValue: nil),
Swift.DecodingError.Context(codingPath: [], debugDescription: "No
value associated with key CodingKeys(stringValue: "_source",
intValue: nil) ("_source").", underlyingError: nil))




Is this due to the json information being an array?.How would I be able to parse this information?










share|improve this question














I am attempting to parse the following json data:



enter image description here



Below is my struct:



struct Album: Decodable 
var source: [Sourcet]
enum CodingKeys: String, CodingKey
case source = "_source"



struct Sourcet: Decodable
var nome, endereco, uf, cidade, bairro: String



let response = try JSONDecoder().decode(Album.self, from: data)



I continue getting the error:




keyNotFound(CodingKeys(stringValue: "_source", intValue: nil),
Swift.DecodingError.Context(codingPath: [], debugDescription: "No
value associated with key CodingKeys(stringValue: "_source",
intValue: nil) ("_source").", underlyingError: nil))




Is this due to the json information being an array?.How would I be able to parse this information?







json swift alamofire jsonparser






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 7 at 2:39









Krunal NagvadiaKrunal Nagvadia

13014




13014












  • Possible duplicate of Swift : The data couldn’t be read because it isn’t in the correct format

    – staticVoidMan
    Mar 8 at 11:19

















  • Possible duplicate of Swift : The data couldn’t be read because it isn’t in the correct format

    – staticVoidMan
    Mar 8 at 11:19
















Possible duplicate of Swift : The data couldn’t be read because it isn’t in the correct format

– staticVoidMan
Mar 8 at 11:19





Possible duplicate of Swift : The data couldn’t be read because it isn’t in the correct format

– staticVoidMan
Mar 8 at 11:19












1 Answer
1






active

oldest

votes


















1














Your struct Album is wrong and you're parsing Album.self single object instead of array.



Try below code :



struct Album: Decodable 
var source: Sourcet // change array to single object
enum CodingKeys: String, CodingKey
case source = "_source"



struct Sourcet: Decodable
var nome, uf : String



To parse json in model :



do 
let response = try JSONDecoder().decode([Album].self, from: data)
for item in response
print(item.source.nome)

catch
print("Error: ",error)






share|improve this answer

























  • it's not work for me

    – Krunal Nagvadia
    Mar 7 at 15:35











  • use edit option and past your full tried code.

    – Pratik Prajapati
    Mar 8 at 3:12












  • it is Rest Api then Above process work?

    – Krunal Nagvadia
    Mar 8 at 3:46











  • what error are you getting ?

    – Pratik Prajapati
    Mar 8 at 4:41











  • can you please write the complete code for call the above json. It is REST Api with Post method

    – Krunal Nagvadia
    Mar 8 at 4:44










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55035215%2fswift-parse-json-error-no-value-associated-with-key-codingkeysstringvalue%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Your struct Album is wrong and you're parsing Album.self single object instead of array.



Try below code :



struct Album: Decodable 
var source: Sourcet // change array to single object
enum CodingKeys: String, CodingKey
case source = "_source"



struct Sourcet: Decodable
var nome, uf : String



To parse json in model :



do 
let response = try JSONDecoder().decode([Album].self, from: data)
for item in response
print(item.source.nome)

catch
print("Error: ",error)






share|improve this answer

























  • it's not work for me

    – Krunal Nagvadia
    Mar 7 at 15:35











  • use edit option and past your full tried code.

    – Pratik Prajapati
    Mar 8 at 3:12












  • it is Rest Api then Above process work?

    – Krunal Nagvadia
    Mar 8 at 3:46











  • what error are you getting ?

    – Pratik Prajapati
    Mar 8 at 4:41











  • can you please write the complete code for call the above json. It is REST Api with Post method

    – Krunal Nagvadia
    Mar 8 at 4:44















1














Your struct Album is wrong and you're parsing Album.self single object instead of array.



Try below code :



struct Album: Decodable 
var source: Sourcet // change array to single object
enum CodingKeys: String, CodingKey
case source = "_source"



struct Sourcet: Decodable
var nome, uf : String



To parse json in model :



do 
let response = try JSONDecoder().decode([Album].self, from: data)
for item in response
print(item.source.nome)

catch
print("Error: ",error)






share|improve this answer

























  • it's not work for me

    – Krunal Nagvadia
    Mar 7 at 15:35











  • use edit option and past your full tried code.

    – Pratik Prajapati
    Mar 8 at 3:12












  • it is Rest Api then Above process work?

    – Krunal Nagvadia
    Mar 8 at 3:46











  • what error are you getting ?

    – Pratik Prajapati
    Mar 8 at 4:41











  • can you please write the complete code for call the above json. It is REST Api with Post method

    – Krunal Nagvadia
    Mar 8 at 4:44













1












1








1







Your struct Album is wrong and you're parsing Album.self single object instead of array.



Try below code :



struct Album: Decodable 
var source: Sourcet // change array to single object
enum CodingKeys: String, CodingKey
case source = "_source"



struct Sourcet: Decodable
var nome, uf : String



To parse json in model :



do 
let response = try JSONDecoder().decode([Album].self, from: data)
for item in response
print(item.source.nome)

catch
print("Error: ",error)






share|improve this answer















Your struct Album is wrong and you're parsing Album.self single object instead of array.



Try below code :



struct Album: Decodable 
var source: Sourcet // change array to single object
enum CodingKeys: String, CodingKey
case source = "_source"



struct Sourcet: Decodable
var nome, uf : String



To parse json in model :



do 
let response = try JSONDecoder().decode([Album].self, from: data)
for item in response
print(item.source.nome)

catch
print("Error: ",error)







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 8 at 6:10

























answered Mar 7 at 3:01









Pratik PrajapatiPratik Prajapati

812721




812721












  • it's not work for me

    – Krunal Nagvadia
    Mar 7 at 15:35











  • use edit option and past your full tried code.

    – Pratik Prajapati
    Mar 8 at 3:12












  • it is Rest Api then Above process work?

    – Krunal Nagvadia
    Mar 8 at 3:46











  • what error are you getting ?

    – Pratik Prajapati
    Mar 8 at 4:41











  • can you please write the complete code for call the above json. It is REST Api with Post method

    – Krunal Nagvadia
    Mar 8 at 4:44

















  • it's not work for me

    – Krunal Nagvadia
    Mar 7 at 15:35











  • use edit option and past your full tried code.

    – Pratik Prajapati
    Mar 8 at 3:12












  • it is Rest Api then Above process work?

    – Krunal Nagvadia
    Mar 8 at 3:46











  • what error are you getting ?

    – Pratik Prajapati
    Mar 8 at 4:41











  • can you please write the complete code for call the above json. It is REST Api with Post method

    – Krunal Nagvadia
    Mar 8 at 4:44
















it's not work for me

– Krunal Nagvadia
Mar 7 at 15:35





it's not work for me

– Krunal Nagvadia
Mar 7 at 15:35













use edit option and past your full tried code.

– Pratik Prajapati
Mar 8 at 3:12






use edit option and past your full tried code.

– Pratik Prajapati
Mar 8 at 3:12














it is Rest Api then Above process work?

– Krunal Nagvadia
Mar 8 at 3:46





it is Rest Api then Above process work?

– Krunal Nagvadia
Mar 8 at 3:46













what error are you getting ?

– Pratik Prajapati
Mar 8 at 4:41





what error are you getting ?

– Pratik Prajapati
Mar 8 at 4:41













can you please write the complete code for call the above json. It is REST Api with Post method

– Krunal Nagvadia
Mar 8 at 4:44





can you please write the complete code for call the above json. It is REST Api with Post method

– Krunal Nagvadia
Mar 8 at 4:44



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55035215%2fswift-parse-json-error-no-value-associated-with-key-codingkeysstringvalue%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved