我有一个结构如下的 JSON 对象:
{
"catNames" : ["a1", "a2", "a3", "a4"],
"dogNames" : ["b1", "b2", "b3", "b4"],
"goldfishNames" : ["c1", "c2", "c3", "c4"]
}
我想要做的事情是解析这个对象并将输入字符串与
"catNames"
、"dogNames"
、"goldfishNames"
进行比较,如果匹配,比如说是catNames
,我想要从catNames
数组中随机输出一个元素。我完全不知所措,该怎么做?