2

I have JSON file in below format. I want to get value i.e. (mouse, aets, infor) using key values.

{
  "list": [
    {
      "item_alias_list": "mouse",
      "eancode": "19",

    },
    {
      "item_alias_list": "aets",
      "eancode": "11",

    },
    {
      "item_alias_list": "infor",
      "eancode": "23",

    }
  ]
}

3 Answers 3

2
var a = {"list":[ 
{

"item_alias_list":"mouse",
"eancode":"19",
}
,   {

"item_alias_list":"aets",
"eancode":"11",
}
,   {

"item_alias_list":"infor",
"eancode":"23",
}
]};

// get "mouse"
var ret = a.list[0].item_alias_list;
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks xdazz in some cases item_alias_list is dynamic so i dont know the key?????
2

Remove the comma after the number strings for valid JSON

2 Comments

comma does not affect any thing
maybe not for this operation... but can cause problems in cases where you need a VALID JSON object
1

you can try this

suppose

var Data =

 {"list":[{"item_alias_list":"mouse","eancode":"19"},
      {"item_alias_list":"aets","eancode":"11"},
      {"item_alias_list":"infor","eancode":"23"}]
 };

var len = Data.list.length;
for(var i = 0; i<len; i++)
{
     for(var key in Data.list[i])
     {
           alert(key +"="+ Data.list[i][key])
     }
}

live Demo : http://jsfiddle.net/PQcFx/40/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.