0

I tried but i was unable to parse this json object which comes from an ashx page.I use javascript serializer to serialize list.I showed the returned json just as it is but when i tried to parse it showed only [object Object],[object Object]. If i change the result to this at ashx page and return string "{ \"Appointment\":"+ return +"}" then jquery doesn't see the post as success and fails to parse it.I use jquery 1.7.1.min.js but there was no way of parsing it.These are the methods i used and the json object i tried to parse

$.ajax({
            type: "POST",
            url: "getappointment.ashx",
            data: { StartTime: timec },
            dataType: "Text",
            success: function (msg) {
                var result = jQuery.parseJSON(msg);
                for (var i in result) {
                    alert(result[i].appointmentID)
                }
            }


        });

1)

 parsed= $.secureEvalJSON(JSON.stringify(json));
   alert(parsed.Appointment[1].appointmentID);

2)

$.each(json.Appointment, function (i, app) {
      alert(json.app.appointmentID.toString());

3)

var test = jQuery.parseJSON(msg);
                alert(test[0].appointmentID);

4)

$.each(msg, function () {
  $.each(this, function (k, v) {
   ...
           });
    });

Json object

[{"appointmentID":"4","coachid":"1","equipmentid":"1","starttime":"18.03.2012 19:14:28","endtime":"18.03.2012 19:14:28"},
{"appointmentID":"8","coachid":"1","equipmentid":"1","starttime":"18.03.2012 19:00:00","endtime":"18.03.2012 19:14:28"}]
15
  • 1
    The JSON you've shown is parsed perfectly: jsfiddle.net/vSA2y Commented Mar 25, 2012 at 22:15
  • $.ajax({ type: "POST", url: "getappointment.ashx", data: { StartTime: timec }, dataType: "json", success: function (msg) { alert(msg); var result = jQuery.parseJSON(msg); alert(result); } }); Commented Mar 25, 2012 at 22:27
  • that one gives [object Object],[object Object] and then "null". Commented Mar 25, 2012 at 22:27
  • so? how is it related to the question? The JSON is valid Commented Mar 25, 2012 at 22:43
  • @zerkms the json looks valid but i'm unable to get the values it writes null to the console either.I showed the whole function so guys might understand if i'm doing anything wrong Commented Mar 25, 2012 at 22:47

2 Answers 2

1

You don't need parse anything - you already have ready to use JSON object.

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

Comments

0

Try var test = JSON.parse(json);

4 Comments

What would it change? The JSON object is valid
That's true, it shouldn't solve his problem. But maybe it gives us further insight about what went wrong.
When i use it as as alert(result[0]); i receive [object Object] at fiddler
@tfeseas: use console.log instead

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.