【发布时间】:2015-01-19 11:07:09
【问题描述】:
我目前正在制作一个应用程序来订购餐点,作为一项小任务的一部分。我有一个 JSON 文件,当您在微调器上选择您想要的餐点时会读取该文件。但我需要一个可以遍历 JSON 文件的 for 循环。
JSON 文件
[
{
Name: "No Meal Selected",
SandPrice: "0.00",
RegPrice: "0.00"
},
{
Name: "OFFER (See Notes)",
SandPrice: "3.79",
RegPrice: "5.29"
},
{
Name: "Whopper",
SandPrice: "3.79",
RegPrice: "5.29"
},
{
Name: "Double Whopper",
SandPrice: "4.79",
RegPrice: "6.29"
},
{
Name: "Whopper Junior",
SandPrice: "2.19",
RegPrice: "3.69"
},
{
Name: "Whopper Bacon And Cheese",
SandPrice: "4.59",
RegPrice: "6.09"
},
{
Name: "Angus XT Steakhouse",
SandPrice: "5.59",
RegPrice: "7.09 "
},
{
Name: "Angus XT Classic",
SandPrice: "5.09",
RegPrice: "6.59 "
},
{
Name: "Angus XT Smoked Bacon And Cheddar",
SandPrice: "5.59",
RegPrice: "7.09 "
},
{
Name: "Angus Steakhouse",
SandPrice: "4.99",
RegPrice: "6.49 "
},
{
Name: "Angus Classic",
SandPrice: "4.49",
RegPrice: "5.99 "
},
{
Name: "Angus Smoked Bacon And Cheddar",
SandPrice: "4.99",
RegPrice: "6.49 "
},
{
Name: "Angus Steakhouse Double",
SandPrice: "5.99",
RegPrice: "7.49 "
},
{
Name: "Angus Classic Double",
SandPrice: "5.49",
RegPrice: "6.99 "
},
{
Name: "Angus Smoked Bacon And Cheddar Double",
SandPrice: "5.99",
RegPrice: "7.49 "
}
]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
JSON i need to loop through
如果有人可以请帮助我,那将非常有帮助,
谢谢。
【问题讨论】:
-
发布您的示例 json
-
[ {Name:"No Meal Selected",SandPrice:"0.00", RegPrice:"0.00" }, {Name:"OFFER (See Notes)",SandPrice:"3.79", RegPrice: "5.29" }, {Name:"Whopper",SandPrice:"3.79", RegPrice:"5.29" }, {Name:"Double Whopper",SandPrice:"4.79", RegPrice:"6.29"}, {Name:" Whopper Junior",SandPrice:"2.19", RegPrice:"3.69"}, {Name:"Whopper Bacon And Cheese",SandPrice:"4.59", RegPrice:"6.09"}, ] 这就是我需要的 for 循环循环遍历
-
更新您的问题
-
你是从 webservice 得到这个?
-
没有来自我保存在 android studio 中的文件