<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>
我有一个url(例如)和它的json值如下:
{"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...
我需要解析它并在我的应用中使用它。 我是javascript的新手。请帮助
答案 0 :(得分:1)
您可以使用jQuery.parseJSON
<强> Live Demo 强>
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);
答案 1 :(得分:0)
var obj = JSON.parse(yourString);
// now use obj.RetVal
答案 2 :(得分:0)
你可以使用这个功能:
var json_obj = JSON.parse("correct_json_format_string");
现在您可以使用json_object访问所有属性:
var return_value = json_obj.RetVal;
希望有所帮助。