如何将转换成字符串的对象,重新转换成对象。具体的就是,将 hash 对象存放到 redis 之后,再取出来,恢复成一个 hash 对象。
比如,我有一个 hash 对象 a1:
[102] pry(main)> a123
=> {"aeopPostCategoryList"=>
[{"id"=>3,
"level"=>0,
"names"=>{"zh"=>"服装/服饰配件", "pt"=>"Vestuário e acessórios", "fr"=>"Vêtements & accessoires", "en"=>"Apparel & Accessories", "ru"=>"Одежда и аксессуары", "es"=>"Ropa y accesorios", "in"=>"Pakaian & aksesoris"},
"isleaf"=>false},
{"id"=>34,
"level"=>0,
"names"=>{"zh"=>"汽车、摩托车", "pt"=>"Automóveis e motos", "fr"=>"Automobiles et motos", "en"=>"Automobiles & Motorcycles", "ru"=>"Автомобили и мотоциклы", "es"=>"Automóviles y motocicletas", "in"=>"Mobil & sepeda motor"},
"isleaf"=>false},
{"id"=>66, "level"=>0, "names"=>{"zh"=>"美容健康", "pt"=>"Beleza e saúde", "fr"=>"Beauté & santé", "en"=>"Beauty & Health", "ru"=>"Красоты и здоровья", "es"=>"Belleza y salud", "in"=>"Kecantikan & kesehatan"}, "isleaf"=>false},
{"id"=>200004360,
"level"=>0,
"names"=>{"zh"=>"俄罗斯当地图书销售", "pt"=>"Livros locais para russo", "fr"=>"Livres pour locale russe", "en"=>"Books for Local Russian", "ru"=>"Книги для местных русский", "es"=>"Libros para Local ruso", "in"=>"Buku untuk lokal Russian"},
"isleaf"=>false},
{"id"=>7,
"level"=>0,
"names"=>{"zh"=>"电脑和办公", "pt"=>"Computador e escritório", "fr"=>"Ordinateur et bureau", "en"=>"Computer & Office", "ru"=>"Компьютер и офиса", "es"=>"Ordenador y oficina", "in"=>"Komputer & kantor"},
"isleaf"=>false},
{"id"=>13,
"level"=>0,
"names"=>
{"zh"=>"建筑", "pt"=>"Construção & Real Estate", "fr"=>"Immobilier & Construction", "en"=>"Construction & Real Estate", "ru"=>"Строительство и недвижимость", "es"=>"Construcción y bienes raíces", "in"=>"Konstruksi & Real Estate"},
"isleaf"=>false},
{"id"=>44,
"level"=>0,
"names"=>{"zh"=>"消费电子", "pt"=>"Eletrônicos de consumo", "fr"=>"Consumer Electronics", "en"=>"Consumer Electronics", "ru"=>"Бытовая электроника", "es"=>"Electrónica de consumo", "in"=>"Elektronik konsumen"},
"isleaf"=>false},
{"id"=>100008578,
"level"=>0,
"names"=>{"zh"=>"定制化产品", "pt"=>"Produtos personalizados", "fr"=>"Produits personnalisés", "en"=>"Customized Products", "ru"=>"Настроенные продукты", "es"=>"Productos personalizados", "in"=>"Produk disesuaikan"},
"isleaf"=>false},
{"id"=>5,
"level"=>0,
"names"=>
{"zh"=>"电气设备和产品",
"pt"=>"Equipamentos eléctricos e suprimentos",
"fr"=>"Electrical Equipment & Supplies",
"en"=>"Electrical Equipment & Supplies",
"ru"=>"Электротехника и дополнения",
"es"=>"Equipo eléctrico y suministros",
"in"=>"Peralatan listrik & perlengkapan"},
"isleaf"=>false},
其存放到 redis 中,再取出来就变成这样了:
"{\"aeopPostCategoryList\"=>[{\"id\"=>3, \"level\"=>0, \"names\"=>{\"zh\"=>\"服装/服饰配件\", \"pt\"=>\"Vestuário e acessórios\", \"fr\"=>\"Vêtements & accessoires\", \"en\"=>\"Apparel & Accessories\", \"ru\"=>\"Одежда и аксессуары\", \"es\"=>\"Ropa y accesorios\", \"in\"=>\"Pakaian & aksesoris\"}, \"isleaf\"=>false}, {\"id\"=>34, \"level\"=>0, \"names\"=>{\"zh\"=>\"汽车、摩托车\", \"pt\"=>\"Automóveis e motos\", \"fr\"=>\"Automobiles et motos\", \"en\"=>\"Automobiles & Motorcycles\", \"ru\"=>\"Автомобили и мотоциклы\", \"es\"=>\"Automóviles y motocicletas\", \"in\"=>\"Mobil & sepeda motor\"}, \"isleaf\"=>false}, {\"id\"=>66, \"level\"=>0, \"names\"=>{\"zh\"=>\"美容健康\", \"pt\"=>\"Beleza e saúde\", \"fr\"=>\"Beauté & santé\", \"en\"=>\"Beauty & Health\", \"ru\"=>\"Красоты и здоровья\", \"es\"=>\"Belleza y salud\", \"in\"=>\"Kecantikan & kesehatan\"}, \"isleaf\"=>false}, {\"id\"=>200004360, \"level\"=>0, \"names\"=>{\"zh\"=>\"俄罗斯当地图书销售\", \"pt\"=>\"Livros locais para russo\", \"fr\"=>\"Livres pour locale russe\", \"en\"=>\"Books for Local Russian\", \"ru\"=>\"Книги для местных русский\", \"es\"=>\"Libros para Local ruso\", \"in\"=>\"Buku untuk lokal Russian\"}, \"isleaf\"=>false}, {\"id\"=>7, \"level\"=>0, \"names\"=>{\"zh\"=>\"电脑和办公\", \"pt\"=>\"Computador e escritório\", \"fr\"=>\"Ordinateur et bureau\", \"en\"=>\"Computer & Office\", \"ru\"=>\"Компьютер и офиса\", \"es\"=>\"Ordenador y oficina\", \"in\"=>\"Komputer & kantor\"}, \"isleaf\"=>false}, {\"id\"=>13, \"level\"=>0, \"names\"=>{\"zh\"=>\"建筑\", \"pt\"=>\"Construção & Real Estate\", \"fr\"=>\"Immobilier & Construction\", \"en\"=>\"Construction & Real Estate\", \"ru\"=>\"Строительство и недвижимость\", \"es\"=>\"Construcción y bienes raíces\", \"in\"=>\"Konstruksi & Real Estate\"}, \"isleaf\"=>false}, {\"id\"=>44, \"level\"=>0, \"names\"=>{\"zh\"=>\"消费电子\", \"pt\"=>\"Eletrônicos de consumo\", \"fr\"=>\"Consumer Electronics\", \"en\"=>\"Consumer Electronics\", \"ru\"=>\"Бытовая электроника\", \"es\"=>\"Electrónica de consumo\", \"in\"=>\"Elektronik konsumen\"}, \"isleaf\"=>false}, {\"id\"=>100008578, \"level\"=>0, \"names\"=>{\"zh\"=>\"定制化产品\", \"pt\"=>\"Produtos personalizados\", \"fr\"=>\"Produits personnalisés\", \"en\"=>\"Customized Products\", \"ru\"=>\"Настроенные продукты\", \"es\"=>\"Productos personalizados\", \"in\"=>\"Produk disesuaikan\"}, \"isleaf\"=>false}, {\"id\"=>5, \"level\"=>0, \"names\"=>{\"zh\"=>\"电气设备和产品\", \"pt\"=>\"Equipamentos eléctricos e suprimentos\", \"fr\"=>\"Electrical Equipment & Supplies\", \"en\"=>\"Electrical Equipment & Supplies\", \"ru\"=>\"Электротехника и дополнения\", \"es\"=>\"Equipo eléctrico y suministros\", \"in\"=>\"Peralatan listrik & perlengkapan\"}, \"isleaf\"=>false}, {\"id\"=>502, \"level\"=>0, \"names\"=>{\"zh\"=>\"电子元器件\", \"pt\"=>\"Componentes e sistemas electrónicas\", \"fr\"=>\"Composants électroniques et les\", \"en\"=>\"Electronic Components & Supplies\", \"ru\"=>\"Электронных компонентов и расходных материалов\", \"es\"=>\"Componentes y sistemas electrónicos\", \"in\"=>\"Komponen elektronik & perlengkapan\"}, \"isleaf\"=>false}, {\"id\"=>2, \"level\"=>0, \"names\"=>{\"zh\"=>\"食品\", \"pt\"=>\"Alimentos\", \"fr\"=>\"Alimentaire\", \"en\"=>\"Food\", \"ru\"=>\"Питание\", \"es\"=>\"Alimentos\", \"in\"=>\"Makanan\"}, \"isleaf\"=>false}, {\"id\"=>1503, \"level\"=>0, \"names\"=>{\"zh\"=>\"家具和室内装饰品\", \"pt\"=>\"Móveis\", \"fr\"=>\"Meubles\", \"en\"=>\"Furniture\", \"ru\"=>\"Мебель\", \"es\"=>\"Muebles\", \"in\"=>\"Furniture\"}, \"isleaf\"=>false}, {\"id\"=>200003655, \"level\"=>0, \"names\"=>{\"zh\"=>\"假发及周边\", \"pt\"=>\"Cabelo e acessórios\", \"fr\"=>\"Cheveux et accessoires\", \"en\"=>\"Hair & Accessories\", \"ru\"=>\"Волосы и аксессуары\", \"es\"=>\"Pelo y accesorios\", \"in\"=>\"Rambut & aksesoris\"}, \"isleaf\"=>false}, {\"id\"=>42, \"level\"=>0, \"names\"=>{\"zh\"=>\"五金\", \"pt\"=>\"Hardware\", \"fr\"=>\"Matériel\", \"en\"=>\"Hardware\", \"ru\"=>\"Оборудование\", \"es\"=>\"Hardware\", \"in\"=>\"Hardware\"}, \"isleaf\"=>false}, {\"id\"=>15, \"level\"=>0, \"names\"=>{\"zh\"=>\"家居用品\", \"pt\"=>\"Casa e jardim\", \"fr\"=>\"Maison & jardin\", \"en\"=>\"Home & Garden\", \"ru\"=>\"Дома и сада\", \"es\"=>\"Hogar y jardín\", \"in\"=>\"Home & Garden\"}, \"isleaf\"=>false}, {\"id\"=>6, \"level\"=>0, \"names\"=>{\"zh\"=>\"家用电器\", \"pt\"=>\"Eletrodomésticos\", \"fr\"=>\"Appareils ménagers\", \"en\"=>\"Home Appliances\", \"ru\"=>\"Бытовая техника\", \"es\"=>\"Electrodomésticos\", \"in\"=>\"Peralatan rumah\"}, \"isleaf\"=>false}, {\"id\"=>200001996, \"level\"=>0, \"names\"=>{\"zh\"=>\"工业/原材料/商业用品\", \"pt\"=>\"Indústria e negócios\", \"fr\"=>\"Industrie et d'affaires\", \"en\"=>\"Industry & Business\", \"ru\"=>\"Промышленности и бизнес\", \"es\"=>\"Industria y negocio\", \"in\"=>\"Industri & bisnis\"}, \"isleaf\"=>false}, {\"id\"=>36, \"level\"=>0, \"names\"=>{\"zh\"=>\"珠宝手表\", \"pt\"=>\"Jóias & relógios\", \"fr\"=>\"Bijoux et montre\", \"en\"=>\"Jewelry & Watch\", \"ru\"=>\"Ювелирные изделия и часы\", \"es\"=>\"Joyería y reloj\", \"in\"=>\"Perhiasan & menonton\"}, \"isleaf\"=>false}, {\"id\"=>39, \"level\"=>0, \"names\"=>{\"zh\"=>\"照明灯饰\", \"pt\"=>\"Luzes\", \"fr\"=>\"Lumières et éclairage\", \"en\"=>\"Lights & Lighting\", \"ru\"=>\"Огни и освещение\", \"es\"=>\"Luces e iluminación\", \"in\"=>\"Lampu & pencahayaan\"}, \"isleaf\"=>false}, {\"id\"=>1524, \"level\"=>0, \"names\"=>{\"zh\"=>\"箱包\", \"pt\"=>\"Bagagem & Bags\", \"fr\"=>\"Bagages et sacs\", \"en\"=>\"Luggage & Bags\", \"ru\"=>\"Багажа и сумки\", \"es\"=>\"Equipaje y bolsas\", \"in\"=>\"Bagasi & tas\"}, \"isleaf\"=>false}, {\"id\"=>1501, \"level\"=>0, \"names\"=>{\"zh\"=>\"孕婴童\", \"pt\"=>\"Mãe & Kids\", \"fr\"=>\"Mère et enfants\", \"en\"=>\"Mother & Kids\", \"ru\"=>\"Мать и дети\", \"es\"=>\"La madre y de los niños\", \"in\"=>\"Ibu & anak-anak\"}, \"isleaf\"=>false}, {\"id\"=>21, \"level\"=>0, \"names\"=>{\"zh\"=>\"办公文教用品\", \"pt\"=>\"Escritório e material escolar\", \"fr\"=>\"Bureau et fournitures scolaires\", \"en\"=>\"Office & School Supplies\", \"ru\"=>\"Офисные и школьные принадлежности\", \"es\"=>\"Office & School Supplies\", \"in\"=>\"Office & School Supplies\"}, \"isleaf\"=>false}, {\"id\"=>509, \"level\"=>0, \"names\"=>{\"zh\"=>\"电话和通讯\", \"pt\"=>\"Telefones e telecomunicações\", \"fr\"=>\"Téléphones et télécommunications\", \"en\"=>\"Phones & Telecommunications\", \"ru\"=>\"Телефоны и телекоммуникации\", \"es\"=>\"Teléfonos y telecomunicaciones\", \"in\"=>\"Ponsel & telekomunikasi\"}, \"isleaf\"=>false}, {\"id\"=>30, \"level\"=>0, \"names\"=>{\"zh\"=>\"安全防护\", \"pt\"=>\"Segurança e proteção\", \"fr\"=>\"Sécurité et Protection\", \"en\"=>\"Security & Protection\", \"ru\"=>\"Безопасности и защиты\", \"es\"=>\"Seguridad y protección\", \"in\"=>\"Keamanan & perlindungan\"}, \"isleaf\"=>false}, {\"id\"=>322, \"level\"=>0, \"names\"=>{\"zh\"=>\"鞋子\", \"pt\"=>\"Sapatos\", \"fr\"=>\"Chaussures\", \"en\"=>\"Shoes\", \"ru\"=>\"Обувь\", \"es\"=>\"Zapatos\", \"in\"=>\"Sepatu\"}, \"isleaf\"=>false}, {\"id\"=>200001075, \"level\"=>0, \"names\"=>{\"zh\"=>\"其他特殊类\", \"pt\"=>\"Categoria especial\", \"fr\"=>\"Catégorie spéciale\", \"en\"=>\"Special Category\", \"ru\"=>\"Специальная категория\", \"es\"=>\"Especial categoría\", \"in\"=>\"Kategori khusus\"}, \"isleaf\"=>false}, {\"id\"=>18, \"level\"=>0, \"names\"=>{\"zh\"=>\"运动及娱乐\", \"pt\"=>\"Esporte e lazer\", \"fr\"=>\"Sports & Entertainment\", \"en\"=>\"Sports & Entertainment\", \"ru\"=>\"Спорт и развлечения\", \"es\"=>\"Deportes y entretenimiento\", \"in\"=>\"Olahraga & hiburan\"}, \"isleaf\"=>false}, {\"id\"=>1420, \"level\"=>0, \"names\"=>{\"zh\"=>\"工具\", \"pt\"=>\"Ferramentas\", \"fr\"=>\"Outils\", \"en\"=>\"Tools\", \"ru\"=>\"Инструменты\", \"es\"=>\"Herramientas\", \"in\"=>\"Alat\"}, \"isleaf\"=>false}, {\"id\"=>26, \"level\"=>0, \"names\"=>{\"zh\"=>\"玩具\", \"pt\"=>\"Brinquedos e Hobbies\", \"fr\"=>\"Jouets & loisirs\", \"en\"=>\"Toys & Hobbies\", \"ru\"=>\"Игрушки и хобби\", \"es\"=>\"Juguetes y pasatiempos\", \"in\"=>\"Mainan & hobi\"}, \"isleaf\"=>false}, {\"id\"=>200003498, \"level\"=>0, \"names\"=>{\"zh\"=>\"旅游及代金券\", \"pt\"=>\"Viagens e serviços de cupom\", \"fr\"=>\"Voyage promo Services\", \"en\"=>\"Travel and Coupon Services\", \"ru\"=>\"Путешествия и купон услуги\", \"es\"=>\"Viajes y cupón servicios\", \"in\"=>\"Perjalanan dan jasa kupon\"}, \"isleaf\"=>false}, {\"id\"=>320, \"level\"=>0, \"names\"=>{\"zh\"=>\"婚礼及重要场合\", \"pt\"=>\"Casamentos e eventos\", \"fr\"=>\"Mariages et événements\", \"en\"=>\"Weddings & Events\", \"ru\"=>\"Свадьбы и события\", \"es\"=>\"Bodas y eventos\", \"in\"=>\"Pernikahan & acara\"}, \"isleaf\"=>false}], \"success\"=>true}"
使用,JSON.parse 貌似不行。