1

I'm using $.ajax Get method to get list of JSon objects. My jquery is

 $.ajax({
    url: 'ItemHandler',             
    method: 'GET',
    dataType: 'json'                
                },
complete: function(items) {
    $.each(items,function(i,object){
       alert(object)
     }
   }
});

And the ItemHandler is like this

public void ProcessRequest(HttpContext context)
{
   List<JObject> jsonList = new List<JObject>();
   List<Item> items = GetItems();
   foreach(Item item in items)
   {
     //string str = Append properties with values to the string
      jsonList.Add(JObject.Parse(str));
   }

   context.Response.ContentType = "application/json";
   context.Response.Write(jsonList);
}

From ItemHandler it adds created Json object to the jsonList correctly and write to the context.response. But within the jquery loop it doesn't give me the object. It shows undefined as in the alert. I need to get each object from there.

4
  • Have you tried success? also try to log items before iterating. Commented Jun 22, 2016 at 10:42
  • Yes success doesn't give anything. Commented Jun 22, 2016 at 10:57
  • Hello snj debug and see whether your jsonList contains json string or not if it contains list object then serialize it into the json as per below and pass to front end. Commented Jun 22, 2016 at 11:40
  • Thanks. It's working now. In my json list some objects has special characters like "\". In this case it's not showing withing the jquery. How to handle this special characters with json.net. Commented Jun 23, 2016 at 4:37

1 Answer 1

2

Pass following in response

JsonConvert.SerializeObject(jsonList);

this will convert your result into json.

Sign up to request clarification or add additional context in comments.

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.