delphi json解析(delphi 怎么写json 接口)
本文目录
- delphi 怎么写json 接口
- 如何解析DELPHI XE5服务器返回的JSON数据及中文乱码
- delphi 抓取多页网页数据
- delphi怎么得到下面的json数据中的多个节点值
- delphi2010怎么加json工具
- delphi7中IDHTTP控件GET一个JSON页面返回乱码
- delphijson转dataset速度慢
- Delphi 中的JSON问题
- Delphi中JSON回车换行符转义
delphi 怎么写json 接口
用js的ajax,这个是jquery的一个简单例子,纯js的会稍微复杂点,
$.ajax({
type: "post",//请求方式
dataType: "json",//数据类型
url: "",//请求地址
success: function (msg) {
//成功之后调用
}
});
如何解析DELPHI XE5服务器返回的JSON数据及中文乱码
这是unicode编码,不是乱码,你进行Unicode转码就出来了 给你写个方法转码,将unicode传递进去返回字符串 public String convert(String utfString){StringBuilder ** = new StringBuilder();int i = -1;int pos = 0;while((i=utfString.indexOf("\...
delphi 抓取多页网页数据
用 delphi 编写抓取多页网页上的数据,其步骤如下:
1、先获取每页的页面地址,一般来说,这些 url 地址都是有规律变化的。
2、遍历上面的页面地址列表,抓取页面上的数据。
此外,某些网页采用 ajax 技术,这种情况下,获取的是服务器的返回数据(比如 json 格式)。
delphi怎么得到下面的json数据中的多个节点值
Delphi下解析json可以去下载一个superobject单元,关于这个单元的使用可以百度一下,很好用的
Delphi/Pascal code?
// Sample 2: how to get child type and subobject fields
//
// Leonid Koninin, 02/03/2007
program sample2;
{$APPTYPE CONSOLE}
uses SysUtils, uLkJSON in ’uLkJSON.pas’;
var JSon, XJSon :TlkJSONobject; JSonNode :TlkJSONString; JSonNodeList :TlkJSONlist; Str :String; i :Integer;
begin
Str := ’{"string1":"one", "string2":"two", ’
+’"childobject" : {"objstr1" :"Oone", "objstr2" :"Otwo"},’
+’"childobject2":}’; writeln(Str);
JSon := TlkJSON.ParseText(Str) as TlkJSONobject; // restore object (parse text)
if not assigned(JSon) then begin // how to obtain type of child
writeln(’error: xs not assigned!’); readln; //exit;
end else begin //Field is 方式判断类型
if JSon.Field is TlkJSONString then writeln(’type: xs is string!’); //string
if JSon.Field is TlkJSONlist then writeln(’type: xs is list!’); //list 多个Json子节点
if JSon.Field is TlkJSONobject then writeln(’type: xs is object!’); //Oject 单个json子节点
//以下类型,实际不常用
if JSon.Field is TlkJSONnumber then writeln(’type: xs is number!’); //数字 value前后不加引号
if JSon.Field is TlkJSONboolean then writeln(’type: xs is boolean!’); //boolean
if JSon.Field is TlkJSONnull then writeln(’type: xs is null!’); //Null 改为空格值
end;
//Filed.SelfType 方式判断类型
case JSon.Field.SelfType of //the other way (0.93+)
jsString :writeln(’other type: xs is string’);
jsObject :writeln(’other type: xs is object’);
jsList :writeln(’other type: xs is list’);
jsNumber :writeln(’other type: xs is number’);
jsBoolean :writeln(’other type: xs is boolean’);
jsNull :writeln(’other type: xs is null’);
jsBase :writeln(’other type: xs is base’);
end;
writeln(’self-type name: ’, JSon.Field.SelfTypeName);
XJSon :=JSon.Field as TlkJSONobject; //JSON中,有下级节点的,不像xml那样称为节点对象,仍称为JSOn对象
//Field as方式取值,完美
JSonNode :=XJSon.Field as TlkJSONString; //we know what xs chilren are strings
writeln(JSonNode.value);
JSonNode :=XJSon.Field as TlkJSONstring;
writeln(JSonNode.value);
//getstring,快速
writeln(XJSon.getString(’objstr1’)); //new v0.99 +syntax!
writeln(XJSon.getString(’objstr2’)); readln;
JSon.Free;
end.
delphi2010怎么加json工具
delphi自带的
System.json; // Dephi自带的JSON单元
var
JSONObject: TJSONObject; // JSON类 定义
{ 从字符串生成JSON }
JSONObject := TJSONObject.ParseJSONValue(Trim(Memo1.Text)) as TJSONObject;
if JSONObject.Count 》 0 then 。。。。。
delphi7中IDHTTP控件GET一个JSON页面返回乱码
流你可以转换一下编码.
Var
strStream:Tstringstream;
begin
strStream :=Tstringstream.create(’’,936); //中文编码
Showmessage(strStream.Datastring);
end;
试试看可以不.我这只有D XE版本.
delphijson转dataset速度慢
delphijson转dataset速度慢是因为数据都是查询循环输出的。解决方法是把键名缩短也变相压缩了JSON文本长度。
Delphi 中的JSON问题
因为Data中没有scene.
Data := TJSONObject.Create;
try
Data.AddPair(’action_name’, ’QR_LIMIT_STR_SCENE’);
Data.AddPair(’action_info’, TJSONObject.Create);
with Data.Values as TJSONObject do
begin
AddPair(’scene’, TJSONObject.Create);
with (Data.Values as TJSONObject do
begin
AddPair(’scene_str’, ’一个字符串’);//为什么在这行出错?
end;
end;
finally
Data.****;
end;
Delphi中JSON回车换行符转义
Delphi使用json作为标准对接的时候,如果入参含有回车和换行符那么会破坏原json数据结构。导致服务端处理异常。这个时候就需要对输入的json字符串进行转义。
首先Delphi中#13代表回车,#10代表换行。所以在转义的时候这2种情况都要考虑到。
比如原JSON字符串 stJson ,转义如下:
stJson:=StringReplace (stJson, #13 ’\\r’, );
stJson:=StringReplace (stJson, #10 ’\\n’, );