Jump to content


Photo

Parse a json with arrays inside it


  • Please log in to reply
3 replies to this topic

#1 netpumber

netpumber
  • Members
  • PipPipPip
  • Advanced Member
  • 107 posts

Posted 11 July 2014 - 01:54 PM

Hello.

 

Server returns this json

{"status":1,"job_status":"READY","iterations":["Contig2","Contig75"],"accessions":["NP_001061702","NP_001068174"]}

And i would like to print out in a textarea (using the above jQuery command)

$('#info').val()

something like this:

 

Contig2 : NP_001061702

Contig75 : NP_001068174

 

Any idea on how to achieve this?

 

Thanks!



#2 requinix

requinix
  • Administrators
  • Lazy Administrator
  • 9,242 posts
  • LocationWA

Posted 11 July 2014 - 09:56 PM

When you did the AJAX stuff you had the option to specify the type of data to return. Tell jQuery to use JSON. Then you'll get an object in your callback function with .status and .job_status and such.
The Reimann Zeta Function Trolley Problem | "Summer is when I, the great ice fairy, can show my true power!"

#3 netpumber

netpumber
  • Members
  • PipPipPip
  • Advanced Member
  • 107 posts

Posted 13 July 2014 - 03:33 PM

Yeah i know that, but i don't know how to parse the Arrays inside that json object. 

 

To print out the status i can write this :

$('#info').val(json.status)

but how can i write down data from the arrays in the form i wrote before ?



#4 requinix

requinix
  • Administrators
  • Lazy Administrator
  • 9,242 posts
  • LocationWA

Posted 13 July 2014 - 11:39 PM

You don't have to do any parsing. It's done for you.

If you're looking to get the Contig2 value, that'd be .iterations[0].
The Reimann Zeta Function Trolley Problem | "Summer is when I, the great ice fairy, can show my true power!"




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users