1
$.ajax({
                url: "/url/url.ajax?length=100000&startDate=2018-07-01",
                method: "get",
                dataType: "json",
                success: function (jdata) {
                    var jsonData=JSON.parse(jdata.data);
                }
            });

respond Json:

{startIndex: 0, draw: 0, recordsTotal: 22, recordsFiltered: 22, pageNumber: 0,…}
data: [{,…}, {,…}, {,…}, {,…},…]
0: {,…}
1: {,…}
2: {,…}
3: {,…}
4: {shequData: {specialFlag: null, userCode: "17110000003", passportNo: "T02221", id: null,…},…}
5: {,…}
6: {,…}
7: {,…}
8: {,…}
9: {,…}
10: {,…}
11: {,…}
12: {,…}
13: {,…}
14: {shequData: {specialFlag: null, userCode: "ZY88888", passportNo: "Z01917", id: null,…}, remark: null,…}
15: {,…}
16: {,…}
17: {,…}
18: {,…}
19: {,…}
20: {,…}
21: {,…}
draw: 0
pageNumber: 0
recordsFiltered: 22
recordsTotal: 22
startIndex: 0

the json has more than 100000 characters, so i post preview of json

for var jsonData=JSON.parse(jdata.data); i got error Uncaught SyntaxError: Unexpected token o in JSON at position 1 how to fix this error?

2 Answers2

2

Have you tried removing JSON.parse();

So just do the following and work directly with that. It's already JSON.

   var jsonData=jdata;

You could try something like this to test it.

  console.log(jdata.recordsFiltered);

Apologies for not putting this as a comment, I don't have enough of a score so not allowed to comment.

Whistler1
  • 47
  • 7
2

No need to use parse again , its already json

$.ajax({
                url: "/url/url.ajax?length=100000&startDate=2018-07-01",
                method: "get",
                dataType: "json",
                success: function (jdata) {
                    var jsonData=jdata.data;
                }
            });

$.ajax({
                url: "https://jsonplaceholder.typicode.com/posts",
                method: "get",
                dataType: "json",
                success: function (jdata) {
                    var jsonData=jdata
                    console.log(jsonData)
                }
            });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Reetesh Kumar
  • 452
  • 2
  • 8