2017-10-06 53 views
-1

有格式的JSON文件,如下所示:我如何将数据存储到数组从JSON

{ 
    "recipe_type": [ 
    "vegetarian", 
    "non-vegetarian" 
    ], 
    "recipe_times": [ 
    "<30min", 
    "30-60min", 
    "60-90min" 
    ], 
    "recipe_cuisines": [ 
    "arabian", 
    "european", 
    "Indian", 
    "chinese" 
    ] 
} 

我需要存储每个列表独立阵列:

@recipe = new JS.M.Recipe() 
@recipe.fetch(@recipe.getRecipeType()) 
@recipeTypes = @recipe.getRecipeType()//Here data is getting as objetcs..if i use alert to print this. It showing output like "[object Object]".. 

我想存储数据如下:

@recipe_type = @recipeTypes.get("recipe_type") 
@recipe_times = @recipeTypes.get("recipe_times")//This is wrong 

我该如何实现我想要的?

回答

0

如果您使用的是主干,那么您必须在页面上加载underscorejs。如果是的话,这应该适合你 lists = _.values(data) 其中数据是上面提到的JSON对象。

相关问题