最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to consume a JSON endpoint? - Stack Overflow

programmeradmin2浏览0评论

So I have been supplied an URL for an "exposed JSON endpoint" similar to one found here-only difference is the functions are different. First of all what does this mean("exposed JSON endpoint") ? 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. But with this, I have no idea how to use the service. (any code in Javascript, C#, Java is fine). Thanks for any help !

So I have been supplied an URL for an "exposed JSON endpoint" similar to one found here-only difference is the functions are different. First of all what does this mean("exposed JSON endpoint") ? 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. But with this, I have no idea how to use the service. (any code in Javascript, C#, Java is fine). Thanks for any help !

Share Improve this question edited Oct 8, 2015 at 2:51 Jenna Maiz asked Oct 8, 2015 at 2:03 Jenna MaizJenna Maiz 8126 gold badges20 silver badges39 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2

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.

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.

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/piler?js"/></script>

Then you call the service using something like this

try {

pilerService.pile(
    {
        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);
}
发布评论

评论列表(0)

  1. 暂无评论