//组装Json串发送
var
JSONObject, JSONObject1: TJSONObject; // JSON类
jsonArray: TJSONArray; // JSON数组变量
strJson: string;
i: Integer;
begin
try
JSONObject := TJSONObject.Create;
JSONObject.AddPair('type', TJSONNumber.Create(1));
JSONObject.AddPair('sKey', TJSONString.Create(config.关键词));
JSONObject.AddPair('sContains', TJSONString.Create(config.包含));
JSONObject.AddPair('price_L', TJSONNumber.Create(config.价格_低));
JSONObject.AddPair('price_H', TJSONNumber.Create(config.价格_高));
JSONObject.AddPair('sExclude', TJSONString.Create(config.排除));
jsonArray := TJSONArray.Create;
JSONObject.AddPair('sContainslst', jsonArray);
for i := 0 to Length(config.筛选) - 1 do
begin
JSONObject1 := TJSONObject.Create;
JSONObject1.AddPair(config.筛选[i].key, TJSONString.Create(config.筛选[i].value));
jsonArray.Add(JSONObject1);
end;
//发送扫货配置
strJson := JSONObject.ToJSON;
sgcWebSocketServer1.WriteData(Guid, strJson);
except
end;
end;
//读取Json值
var
tmpJsonObject: TJSONObject;
tmpJsonArr: TJSONArray;
i: Integer;
tmpShopInfo: TShopInfo;
begin
try
Result := False;
tmpJsonObject := TJSONObject.ParseJSONValue(sJson) as TJSONObject;
if tmpJsonObject <> nil then
begin
tmpJsonArr := tmpJsonObject.GetValue<TJsonArray>('items');
if tmpJsonArr <> nil then
begin
for i := 0 to tmpJsonArr.Size - 1 do
begin
tmpShopInfo.mall_ID := (tmpJsonArr.Get(i) as TJSONObject).GetValue<string>('item_data.goods_model.mall_id');
tmpShopInfo.saleCount := (tmpJsonArr.Get(i) as TJSONObject).GetValue<string>('item_data.goods_model.sales_tip');
g_ShopInfoList.Add(tmpShopInfo);
end;
end;
end;
except
on e: Exception do
begin
Log(e.Message);
end;
end;
end;
05-27
464
