0

In my project I need to aggregate many data in one string and later parse it out. The data is related to people, it need to record people_ids in different state and age group, and their counts. For example, we have 5 people named John Smith in CA, 2 people between 20-29, 2 between 30-39, 1 between 40-49; 2 people named John Smith in NY, 1 between 20-29 and 1 between 30-39. Then the string will be somewhat like this,

John smith| [CA#5: 20-29#2{pid_1, pid_2};30-39#2{pid_3,pid_4};40-49#1{pid_5}] [NY#2: 20-29#1{pid_6};30-39#1{pid_7}] 

It not necessarily be the same format, but whatever format easy to parse out. Is there any good way to do this? How about Json format? And if it looks like the above format, if I want all John Smith in CA between age 30-39, how should I parse out the data? Thanks a lot!!

4

1 回答 1

2

根据我对您帖子的理解,这可能是您正在寻找的格式(以 JSON 表示)。

请记住,有些 gem 可以为您生成和解析 JSON。

{
    "name": "John Smith",
    "states": {
        "CA": {
            "total": 5,
            "ages": {
                "20-29": [pid_1, pid_2],
                "30-39": [pid_3, pid_4],
                "40-49": [pid_5]
            }
        },
        "NY": {
            "total": 2,
            "ages": {
                "20-29": [pid_6],
                "30-39": [pid_7]
            }
        }
    }
}
于 2012-08-08T19:13:20.077 回答