[{"TestNum":1,"TestItem":"What is JS","TestA":"JAVA SCRIPT","TestB":"JAVA SAMPLE","TestC":"JAVA SERVER","TestD":"JAVA SAFE","TestAnswer":"A"},
{"TestNum":2,"TestItem":"Where is USA","TestA":"NEXT TO CANADA","TestB":"NEXT TO AFRICA","TestC":"NEXT TO CHINA","TestD":"NEXT TO AMERICA","TestAnswer":"A"},
{"TestNum":3,"TestItem":"Which is a mobile os","TestA":"UBUNTU","TestB":"OSX","TestC":"WINDOWS","TestD":"WP","TestAnswer":"D"}]
这是一个测验json文件,我尝试在jQuery mobile中使用ajax,通过推送NEXTBOTTON使其显示下一个问题,如测验,但结果只是让我感到困惑,它将显示所有的测试答案。我是jQuery的新手,在C#中我可以使用List<T>[int]
来显示每个角色。有人请帮我解决这个问题。非常感谢!!
答案 0 :(得分:0)
使用 JSON.parse() 将JSON字符串读入JSON对象。
一旦你拥有了这个对象,它将是一个问题对象数组,例如,要获得第一个问题的TestItem属性,你会写:
var questions = JSON.parse(data);
var testitem1 = questions[0].TestItem;
数据是AJAX调用返回的JSON字符串。