0

I am receiving a json_encode string into javascript with the following format:

["eq:22","dkdkd",1,0,1,1,1,1,1]

How do I parse this string to use in javascript. I want to separate all values by comma into an array, if possible. Can someone please point me into the right direction on how to do this?

Jonathan Lonowski
  • 121,453
  • 34
  • 200
  • 199
PL76
  • 83
  • 12

2 Answers2

0

If you're receiving it as a function variable (i.e function myFunc(json_data)), you'll have an indexed array where json_data[0] = "eq:22", json_data[1] = "dkdkd" and so on.

Eduardo Escobar
  • 3,301
  • 2
  • 18
  • 15
0

I think this code will work.Try and please let me know.

function showJSON() {    
    var user =    
    {    
      "username":"andy",    
      "age":20,    
      "info": { "tel": "123456", "cellphone": "98765"},    
      "address":    
      [    
        {"city":"beijing","postcode":"222333"},    
        {"city":"newyork","postcode":"555666"}    
      ]    
    }    

    alert(user.username);    
    alert(user.age);    
    alert(user.info.cellphone);    
    alert(user.address[0].city);    
    alert(user.address[0].postcode);    
}   
Jonathan Lonowski
  • 121,453
  • 34
  • 200
  • 199
Neil.YC
  • 11
  • 4
  • 1
    Note: Your example doesn't use any JSON. The syntax is similar, but this is a [JavaScript Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer) being code. – Jonathan Lonowski Nov 28 '15 at 00:17