如何从一个档案与读取;存储键:value对字符串数组? [英] How to read from a file & store key:value pair in String Array?
本文介绍了如何从一个档案与读取;存储键:value对字符串数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在它下面的数据的咖啡脚本文件。我想创建将下列数据存储为值的字符串数组:它值对。
I have a coffee script file with the following data in it. I want to create a string array that will store the following data as key:value pair in it.
abTests:
productRanking:
version: 4
groups: [
ratio:
default: 1
us: 0.90
me: 0.0
value: "LessPopularityEPC"
,
ratio:
default: 0
us: 0.1
value: "CtrEpcJob"
,
ratio:
default: 0
me: 1.0
value: "RandomPerVisitor"
]
sabt:
version: 1
groups: [
ratio:
default: 1
us: 0.90
value: "default"
,
ratio:
default: 0
us: 0.05
value: "colorBoost"
,
ratio:
default: 0
us: 0.05
value: "colorPriority"
,
ratio:
default: 0
us: 0
value: "noColorClause"
]
我要创建以下格式的这些数据的字符串数组
I want to create a String Array with these data in the following format
productRanking:LessPopularityEPC
productRanking:CtrEpcJob
productRanking:RandomPerVisitor
sabt:default
sabt:colorboost
sabt:colorPriority
sabt:nocolorClause
有什么办法来解决这个问题?
Is there any way to solve this problem??
推荐答案
如果通过字符串数组你的意思是这个
If by String Array you mean this
['productRanking:LessPopularityEPC', 'productRanking:CtrEpcJob', 'productRanking:RandomPerVisitor']
您可以做到这一点下面的CoffeeScript code
You can do that with the following coffeescript code
data = abTests:
...
array = []
for testName,tests of data['abTests']
for categoryName,categoryElems of tests['groups']
array.push (testName + ':' + categoryElems['value'])
console.log array
#=> ['productRanking:LessPopularityEPC', 'productRanking:CtrEpcJob', 'productRanking:RandomPerVisitor']
这篇关于如何从一个档案与读取;存储键:value对字符串数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文