0

I attach here my code please tell me how can i fetch value from this json. for e.g. i want to get value of pms_pro_amt so this will give result 54. This is my json response

    {"obj1": "{u'pms_pro_amt': '54', u'pms_client_cmpname': 'Tata Steels', u'pms_pro_priority': 'medium'
, u'pms_user_master_id': 0, u'pms_client_unique_id': 'c2', u'pms_pro_assign_id': '9', u'pms_pro_start_date'
: datetime.datetime(2016, 3, 1, 0, 0), u'pms_pro_status': 0, u'pms_category_id': 0, u'pms_pro_end_date'
: datetime.datetime(2016, 3, 2, 0, 0), u'pms_pro_desc': 'jhk', u'pms_client_name': 'Ratan Tata', u'pms_pro_id'
: 1, u'pms_pro_attachment': '', u'pms_pro_timespend': '', u'pms_pro_amt_type': 'hourly', u'pms_pro_name'
: 'hj', u'pms_pro_tech': 'Java', u'pms_client_master_id': '2'}", "obj2": "[{u'pms_dev_name': 'gaTes'
}]"}

now i want to set first value to my textbox.This is my jquery code

 var id=$(this).attr("id");
    formdata = new FormData();
    formdata.append('id',id);
    $.ajax({
        url : '/view-project',
        data : formdata,
        type : 'post',
        contentType : false,
        cache : false,
        processData : false,
        success:function(data){
            if (data == 0){
                alert('No data Found');
            }
            else {

                $("#view_pro_client_cmpname").val(data['obj1']);
              }

I'm getting full json response in data variable. Now how to get only one key-value from this Response please help

0

2 Answers 2

2

It looks like your JSON is invalid. But you can get your values like that.

var data = {
  obj1: {
  	param1: 'hey',
        param2: 'you'
  },
  obj2: {
  	param1: 'is'
  }
}

//Show data like this
alert( data['obj1']['param1'] );
// Or like this
alert(data.obj1.param1);

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

Comments

0
$.each($.parseJSON(data), function(key,value){
    alert(value.obj1);
});

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.