Reputation: 631
<script type="text/javascript" src="jquery.mobile/jquery-1.7.2.min"></script>
<script type="text/javascript" src="docs/assets/js/jquery.jsonp.js"></script>
<script>
$(document).ready(function(){
var output = $('#output');
$.ajax({
url: 'http://musi.php/?oper=getds&dev_id=f587&cur_id=2',
dataType: 'jsonp',
jsonp: 'jsoncallback',
timeout: 5000,
success: function(data, status){
$.each(data, function(i,item){
var landmark ='<h1>'+item.Nick_Name+'</h1>';
output.append(landmark);
});
},
error: function(){
output.text('There was an error loading the data.');
}
});
});
</script>
i have a url(for eg) and its json values as follows:
{"RetVal":"Ok","ValueRsp":[{"Feedback_Id":"22","Customer_Id":"543","Feedback_Type_Id":"1","First_Name":"Tester Tester","Last_Name":"NA","Nick_Name":"Xgcfyxfu"}]}
error: invalid label
Line 1 [Break On This Error]
{"RetVal":"Ok","ValueRsp":[{"Feedback_Id":"22","Customer_Id":"543","Feedback_Typ...
i need to parse it and use it in my app. i am new to javascript. kindly help
Upvotes: 1
Views: 1244
Reputation: 148120
You can use jQuery.parseJSON
jsonobj = $.parseJSON('{"RetVal":"Ok","ValueRsp":[{"Feedback_Id":"22","Customer_Id":"543","Feedback_Type_Id":"1","First_Name":"Tester Tester","Last_Name":"NA","Nick_Name":"Xgcfyxfu"}]}');
alert(jsonobj.RetVal);
alert("jsonobj.ValueRsp[0].Customer_Id: " + jsonobj.ValueRsp[0].Customer_Id);
Upvotes: 1
Reputation: 2958
you can use the function:
var json_obj = JSON.parse("correct_json_format_string");
now you can use the json_object ot access all the properties:
var return_value = json_obj.RetVal;
Hope that helps.
Upvotes: 0
Reputation: 14434
a little bit of googling would have done it...
var obj = JSON.parse(yourString);
// now use obj.RetVal
Upvotes: 0