简体   繁体   English

什么是JSON数据源?

[英]What is a JSON Data Source?

I am working on a C# console application using the Nancy Framework and the Spark view engine, and I am trying to replicate something from another project. 我正在使用Nancy Framework和Spark视图引擎在C#控制台应用程序上工作,并且正在尝试从另一个项目中复制某些内容。 However, I am very inexperienced with both Javascript and JSON. 但是,我对Javascript和JSON都缺乏经验。 To call a chat function in my C# code from my HTML, right now I simply use something like the following... 要从我的HTML中用C#代码调用聊天功能,现在,我只需要使用以下内容即可...

HTML: HTML:

http://localhost:1234/sendchat?message="this is a test message"

C# Code: C#代码:

    Get["/sendchat"] = x =>
    {
        string message = Request.Query.message;
        string message2 = message.Replace("\"", "");
        Console.WriteLine(message2);

        return View["console.spark"];
    };

The problem is that this causes the page to reload. 问题在于这会导致页面重新加载。 In the project I am looking at for reference, they use Javascript/JSON to call the same type of function without doing a page reload. 在我正在寻找参考的项目中,它们使用Javascript / JSON来调用相同类型的函数,而无需重新加载页面。 I understand all of it except for the JSON line as I don't understand what the DataSource is... 我了解所有内容,但JSON行除外,因为我不了解数据源是什么...

$(document).ready(function () {
    $("#typechat").keypress(function (event) {
        if (event.keyCode == '13') {
            event.preventDefault();
            message = escape($("#typechat").attr('value'));
            $.getJSON(dataSource + "?req=sendchat&message=" + message);
            $("#typechat").attr('value', "");
        }
    });
});

dataSource is just an http domain like http://yourserver.com/possibly/with/a/path . dataSource只是一个http域,例如http://yourserver.com/possibly/with/a/path It'll be a string defined somewhere in the code. 这将是代码中定义的字符串。

JSON resources are fetched just like regular HTML pages, with a normal GET request over HTTP. JSON资源的获取与常规HTML页面一样,通过HTTP进行常规的GET请求。 The only difference is the content is JSON not HTML. 唯一的区别是内容是JSON而不是HTML。 Try this in your browser for example to see the JSON returned by the SO api: 在浏览器中尝试此操作,例如查看SO api返回的JSON:

http://api.stackoverflow.com/1.1/users/183579 http://api.stackoverflow.com/1.1/users/183579

(If you don't have a browser plugin to format/highlight JSON nicely it might just look like a long messy string) (如果您没有用于很好地格式化/突出显示JSON的浏览器插件,则可能看起来像一个长而乱的字符串)

Data source is propobly some web page 数据源大概是某个网页

dataSource = "http://somepage.com/someaction";

wich renders response as json text, response is grabbed and then parsed to javascript object wich将响应呈现为json文本,获取响应,然后解析为javascript对象

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

相关问题 在什么时候确定LINQ数据源? - At what point is a LINQ data source determined? ActiveReports Server-具有用于分页和筛选的URL参数的JSON数据源 - ActiveReports Server - JSON data source with URL parameters for paging and filtering 使用 Text.Json 和源生成器定义数据 model 的问题 - Problem to define the data model with Text.Json and source generator GridView自动生成列需要具有哪些数据源? - What does the data source need to have for a GridView to autogenerate columns? 在OLEDB连接字符串中,数据源为DATASOURCE = {0}是什么意思? - In OLEDB Connection string ,data source is DATASOURCE = {0} What Does it Mean? 数据绑定/设置源到我的DataGrid [WPF]的正确方法是什么 - What is proper way of data binding / setting source to my DataGrid [WPF] 关键字不支持“数据源”,这是什么错误? - key word not supported “data source” ,what's the error i it? 绑定数据源更新后立即引发什么Textbox事件? - What Textbox event is raised right after bound data source is updated? SQLite连接字符串“ Data Source =:memory:”的用途是什么? - What is the use of SQLite connection string “Data Source = :memory:”? Newtonsoft JSON 找到什么数据 model 是响应 - Newtonsoft JSON find what Data model is in response
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM