completely reformat a json response

I have a .json response that needs to reformatted into a different response that I'll eventually reparse and save for use in a different part of my code elsewhere. I'm not entirely sure how to describe what i'm doing here, but after i know that my arrays are grouped in the proper format, I can parse the json. :-\ Allow me to show you the code, and what the output should look like: current json format:

    {"response":
      {"docs":[
        {"set_number":"1","set_description":"first description","subset_number":"835","subset_description 1":"hello 2" },
        {"set_number":"1","set_description":"first description","subset_number":"845","subset_description 2":"hello 3" },
        {"set_number":"2","set_description":"first description","subset_number":"855","subset_description 3":"hello 4" },
        {"set_number":"2","set_description":"first description","subset_number":"865","subset_description 4":"hello 5" },
        {"set_number":"3","set_description":"first description","subset_number":"875","subset_description 5":"hello 6" },
        {"set_number":"4","set_description":"first description","subset_number":"885","subset_description 6":"hello 7" },
        {"set_number":"4","set_description":"first description","subset_number":"895","subset_description 7":"hello 8" },
        ]
        }
        }
.. and here is what i'm attempting to make it look like:

        {"response":
          {"docs":[

	{
	"set_number":"1","set_description":"first description",
	"subsets":[
		{"subset_number":"845","subset_description 2":"hello 3"},
		{"subset_number":"835","subset_description 1":"hello 2"}
		]
	},
	{
	"set_number":"2","set_description":"first description",
	"subsets":[
		{"subset_number":"855","subset_description 3":"hello 4"},
		{"subset_number":"865","subset_description 4":"hello 5"} 
	},
	{
	"set_number":"3","set_description":"first description",
	"subsets":[
		{"subset_number":"875","subset_description 5":"hello 6"}
		]
	},

	{
	"set_number":"4","set_description":"first description",
	"subsets":[
		{"subset_number":"895","subset_description 7":"hello 8"},
		{"subset_number":"885","subset_description 6":"hello 7"}
		[
	},
          ]
        }
        }

As you can see, I basically combined all the subset information so that the response is cleaner and grouped together. Any assistance would be greatly appreciated!
You want to do it in JavaScript or what?

以上就是completely reformat a json response的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » jQuery 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏