所以,我有一个JSON数组,我通过它循环,并添加三个键及其值,我还想删除/删除数组中每个元素的键(subject_id).
怎么去做这个?
s=JSON.parse(subjects.to_json)
s.each do |j|
j["total_classes"] = total_classes[i]
j["attended_classes"] = attended_classes[i]
j["subject_name"] = subject_name[i]
j["subject_id"] #remove this key, how?
i=i+1
end
render json: { attendances: s }
Run Code Online (Sandbox Code Playgroud)