简体   繁体   English

如何使用JSON端点?

[英]How to consume a JSON endpoint?

So I have been supplied an URL for an "exposed JSON endpoint" similar to one found here -only difference is the functions are different. 因此,为我提供了一个"exposed JSON endpoint"的URL,该URL与此处找到的URL相似-唯一的区别是功能不同。 First of all what does this mean("exposed JSON endpoint") ? 首先,这是什么意思(“暴露的JSON端点”)? And how do I call this web service ? 我怎么称呼这个网络服务? I have used web services like the Google Maps with C# where I would download and parse the XML from URL and use the data. 我曾经使用过Web服务,例如带有C#的Google Maps,可从URL下载并解析XML并使用数据。 But with this, I have no idea how to use the service. 但是,与此有关,我不知道如何使用该服务。 (any code in Javascript, C#, Java is fine). (JavaScript,C#,Java中的任何代码都可以)。 Thanks for any help ! 谢谢你的帮助 !

An "exposed JSON endpoint" is a publicly available URL (sometimes with query or path parameters added by you) which you can send an HTTP request to and it will return JSON from the remote server that is related to the request you sent. “公开的JSON端点”是一个公共可用的URL(有时带有您添加的查询或路径参数),您可以向其发送HTTP请求,并且它将从远程服务器返回与您发送的请求相关的JSON。

You then parse the returned JSON (into the structure of whatever programming language you are using) so you can then use the returned data in your own code. 然后,您可以将返回的JSON(解析为所使用的任何编程语言的结构)进行解析,以便随后可以在自己的代码中使用返回的数据。

Maybe you can try something like this: 也许您可以尝试这样的事情:

WebClient client = new WebClient();
Stream stream = client.OpenRead("Endpoint");
StreamReader reader = new StreamReader(stream);

Newtonsoft.Json.Linq.JObject jObject = Newtonsoft.Json.Linq.JObject.Parse(reader.ReadLine());

As the service end point states: 如服务端点所述:

You need to include the following element in your page 您需要在页面中包含以下元素

<script src="http://orc.csres.utexas.edu/orchard/json/compiler?js"/></script>

Then you call the service using something like this 然后,您使用类似这样的方式致电服务

try {

compilerService.compile(
    {
        devKey : "key", 
        program : "program"
    },
    function(returnValue) { 
        // it worked do something with returnValue
        console.log(returnValue); 
    },
    function(response, status, exception) {
        // something went wrong
        console.log(response);
        console.log(status);
        console.log(exception);
    }
);

}
catch (e) {
    console.log(e);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM