0

I have updated my jSon object using the code

<script type="text/javascript" >
            jQuery(document).ready(function($){
                var lessonId = "3423671";
                $.getJSON('data.json', function(json) {             
                    $.each(json, function(i, data) {
                        $.each(this.courseStarted[0].courseDetails[0].lessonDetails, function(){                            
                            if(this.lessonId == lessonId){                              
                                this.quiz = "This row updated";                             
                            }
                        });
                    });
                });

            });
        </script>

Here i am updating my json object inside the if condition. Is there any method to get me the new updated json object to print into a html div tag as text in the json format.

4

2 回答 2

1

由于json有您的对象数据(从您的服务器检索),并且您的代码刚刚更新了它,您可以使用JSON.stringify(json). AFAIKJSON大多数浏览器都原生支持该对象。

于 2012-06-12T05:52:36.047 回答
0
JSON.stringify({ foo: "lorem", bar: "ipsum" }, null, '\t');

文档

于 2012-06-12T05:59:43.463 回答