在javascript中访问python字典 [英] Accessing python dictionary in javascript

查看:223
本文介绍了在javascript中访问python字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从python发送这个字典:

  {'root':['value','path' 'type'],.......} 

我将它发送到javascript by ajax通过序列化呼叫请求



如何在javascript中访问该字典。



感谢Advance

解决方案

假设您以下面的方式进行AJAX调用,则会将响应命令作为resValue。使用JSON.parse方法

  $。getJSON(/ url,{params},function(data,status, xhr){
$ .each(data.response,function(resKey,resValue){
if(resKey ==success){
var _result = JSON.parse(resValue);
}
}
}


I am sending dictionary from python like this:

{'root':['value','path','type'],.......}

i am send it to javascript by ajax call request by serializing it,

How to access that dictionary in javascript.

thanks in Advance

解决方案

Suppose you are making AJAX call in below way, you will get the response dict as resValue. use JSON.parse method on it

$.getJSON( "/url", {params }, function( data, status, xhr ) {
    $.each(data.response, function(resKey, resValue){
        if(resKey == "success"){
             var _result = JSON.parse(resValue);
        }
    }
}

这篇关于在javascript中访问python字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆