javascript - How to loop through js or jquery to create a json format data?
仅有的幸福
仅有的幸福 2017-05-19 10:43:06
0
4
472

'[{"imgPath": "C","price": "B","specDesc": "C"},{"imgPath": "D","price": "E","specDesc ": "F"}]' This is a parameter for an ajax request. How do I get the data on the page and create it in a loop to form a json? How should I do it? Please answer me! ! !


This is the page

仅有的幸福
仅有的幸福

reply all (4)
滿天的星座

Press the control to take out the value, form an object literal, and then format it into JSON... To determine what kind of data is generated, you need to know how the interface is agreed upon.

Making a pair should be simple, like

var aModel = { imgPath: $("#imgPath").val(), price: $("#price").val() }

Generating JSON is just one sentence

var json = JSON.stringify(aModel)
    黄舟

    JSON.parse()

      仅有的幸福

      var arr = [];
      var param = {}

      $("块").each(funciton(){ var _temp = {"imgPath": "C","price": "B","specDesc": "C"}; arr.push(_temp) }) param.resutl=arr;
        左手右手慢动作

        You can use mockjs to simulate a lot of data.

          Latest Downloads
          More>
          Web Effects
          Website Source Code
          Website Materials
          Front End Template
          About us Disclaimer Sitemap
          php.cn:Public welfare online PHP training,Help PHP learners grow quickly!