最近使用了百度的API功能,但调用方法是这样的http://api.map.baidu.com/ag/coord/convert?from=0&to=4&x=116.254615&y=29.814476 
 
返回格式: 
{"error":0,"x":"MTE2LjI2MTA5OTEyMjE=","y":"MjkuODIwNTYwODc0ODQ2"} 请问各位兄弟,这种方法,在JAVASCRIPT里面怎么调用呀。

解决方案 »

  1.   

    var str = '{"error":0,"x":"MTE2LjI2MTA5OTEyMjE=","y":"MjkuODIwNTYwODc0ODQ2"}';
    var obj = eval('('+ str  +')');
    alert(obj.error)
    alert(obj.x)
    alert(obj.y)
      

  2.   

    http://api.map.baidu.com/ag/coord/convert?from=0&to=4&x=116.254615&y=29.814476这串在JAVASCRIPT和C#里面使用以方法的形式来调用呢。
      

  3.   

    {"error":0,"x":"MTE2LjI2MTA5OTEyMjE=","y":"MjkuODIwNTYwODc0ODQ2"}这串内容是从http://api.map.baidu.com/ag/coord/convert?from=0&to=4&x=116.254615&y=29.814476返回的,我想知道使用调用
      

  4.   

            WebRequest wr = WebRequest.Create("http://api.map.baidu.com/ag/coord/convert?from=0&to=4&x=116.254615&y=29.814476");
            WebResponse wp = wr.GetResponse();
            Stream s = wp.GetResponseStream();
            StreamReader sr = new StreamReader(s);
            string str = sr.ReadToEnd();
            Response.Write(str);
            sr.Dispose();
            s.Dispose();
    要使用 System.Net 和 System.IO命名空间
      

  5.   


    Server Error in '/WebMapinfo' Application.
    --------------------------------------------------------------------------------The remote server returned an error: (407) Proxy Authentication Required. 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Net.WebException: The remote server returned an error: (407) Proxy Authentication Required.Source Error: 
    Line 20: 
    Line 21:         WebRequest wr = WebRequest.Create("http://api.map.baidu.com/ag/coord/convert?from=0&to=4&x=116.254615&y=29.814476");
    Line 22:         WebResponse wp = wr.GetResponse();
    Line 23:         Stream s = wp.GetResponseStream();
    Line 24:         StreamReader sr = new StreamReader(s);
     返回了这个错误
      

  6.   

    可以返回了,原因是我上网是通过公司代理出去的,换成直连外网就可以了,有没有方法实现通过代理上网,也可以调用INTERNET的功能。
      

  7.   

            //设置代理
            WebProxy proxy = new WebProxy("proxy.cccil.com",8000);
            proxy.Credentials = new NetworkCredential("km35609", "qwe1234!", "proxy.cccil.com");
            //访问baidu方法
            WebRequest wr = WebRequest.Create("http://api.map.baidu.com/ag/coord/convert?from=2&to=4&x=116.254615&y=29.814476");
            wr.Proxy = proxy;
            WebResponse wp = wr.GetResponse();
            Stream s = wp.GetResponseStream();
            StreamReader sr = new StreamReader(s);
            string str = sr.ReadToEnd();
            Response.Write(str);
            sr.Dispose();
            s.Dispose();已解决,请各位高手提供下JAVASCRIPT的方法
      

  8.   

        $(function () {
            $.getJSON("http://api.map.baidu.com/ag/coord/convert?callback=?", {
                from: 2,
                to: 4,
                x: 116.254615,
                y: 29.814476
            }, function (data) {
                alert(data.x);
            });
        });因为已经涉及到跨域访问,如果用纯javascript解决的话会比较麻烦,但是用jquery的getJSON就比较方便了
      

  9.   

    我还是想用你这种方法以,能再说详细点吗?我对JSON不熟悉
      

  10.   

    引用jquery文件,然后    $(function () { // 这个是页面加载完成之后自动调用的时候,你可以根据需求改成onclick之类触发
            $.getJSON("http://api.map.baidu.com/ag/coord/convert?callback=?", 
            {//这里是你那个url的参数
                from: 2, 
                to: 4,
                x: 116.254615,
                y: 29.814476
            }, 
            function (data) {
             //这里就是那个baidu页面返回的数据 {"error":0,"x":"MTE2LjI2MTA5OTEyMjE=","y":"MjkuODIwNTYwODc0ODQ2"}  
    //比如要获得 error的代码,就用  data.error 来获取, x就是data.x,y就是data.y,这就是json格式
                alert(data.x);
            });
        });