0

I am getting following values from server

{"status":{"message":"success","code":200},"data":[{"sent":"test","category":"Appo","experience_time":"2014-10-07","sent_id":4501922,"categoryId":4011,"score":"Negative","feature":"emp","op":"challenges"}]}

I need to get the value of sent,category,experience_time,sent_id,score,feature,op etc

I have tried following so far.But not getting any value.

 var result = jQuery.parseJSON(data);

          $.each(result, function(index, value) {

alert(value.score);

        });
3
  • 3
    You need to use $.each(result.data, function(index, value) {}); since result.data contains the array you want to iterate over Commented Oct 29, 2014 at 6:38
  • also make sure that data is a string not a object before calling jQuery.parseJSON(data) - check your browser console to see whether there are any errors? Commented Oct 29, 2014 at 6:40
  • try this,alert(data['score']); Commented Oct 29, 2014 at 6:46

1 Answer 1

1

try this,

var jsonString = '{"status":{"message":"success","code":200},"data":[{"sent":"test","category":"Appo","experience_time":"2014-10-07","sent_id":4501922,"categoryId":4011,"score":"Negative","feature":"emp","op":"challenges"}]}';


var result = jQuery.parseJSON(jsonString);

$.each(result.data, function(index, value) {

  alert(value.score);

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

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.