Link to home
Create AccountLog in
Avatar of Black_Trash
Black_Trash

asked on

JSON parse a string from web service jQuery

Hi,
  How would you parse the following JSON string that is being returned from a web service using jQuery?

Part of the string = {"NewDataSet":{"Inventory":[{"MOVE_ID":....

Set a variable that would contain the value of MOVE_ID.

Thanks,
Keith
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Go to

http://www.jsoneditoronline.org/

and you will see

	
object		{1}
  NewDataSet		{1}
    Inventory		[2]
      0		{1}
        MOVE_ID	:	id1
      1		{1}
        MOVE_ID	:	id2
[code]
if you give it 
[code]
 {"NewDataSet":{
   "Inventory":[
      {"MOVE_ID":"id1"},
      {"MOVE_ID":"id2"}
    ]
  }
}

Open in new window


so you will have
$.get("url",function(data) {
   window.console && console.log(data);
   window.console && console.log(data.NewDataSet.Inventory[0].MOVE_ID);
});

Open in new window

Hi,

If you are familiar with LINQ, you may want to have a look at LINQ-TO-JSON:

http://james.newtonking.com/projects/json/help/index.html?topic=html/LINQtoJSON.htm

Giannis
How are you calling the webservice - from JQuery?

If so, if you are using $.post or $.ajax then you have an option in these functions of having JQuery automatically parse the json for you ex
var moveid;
$.post(url, data, function(response) {
  // use parsed JSON response here 
  moveid = response. ... .MOVE_ID; // Fill in missing path as needed  
},'json');

Open in new window

@jyparask it is altready in JSON
@julianH yes he is and the "Fill in missing path" is the actual question
I didn't say it is not a JSON.

LINQ-TO-JSON is a mean of parsing the JSON using the power of LINQ. Of course this would need server side processing, so i don't know if this is acceptable here. But if it is, i find it really useful.

Giannis
@julianH yes he is and the "Fill in missing path" is the actual question
I don't agree - question asks how to parse JSON response and only a part of the response is given.
To properly answer your interpretation of the question would require the poster post the entire JSON response - not just part of it.
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Black_Trash
Black_Trash

ASKER

Sorry, thought I had already posted an accept on the solution

Thanks,
Keith Black