|
|
@@ -3,6 +3,9 @@ using System;
|
|
|
using System.IO;
|
|
|
using System.Runtime.Serialization;
|
|
|
using System.Windows.Forms;
|
|
|
+using Newtonsoft.Json;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Text.RegularExpressions;
|
|
|
|
|
|
namespace UAS_Web.tool
|
|
|
{
|
|
|
@@ -12,12 +15,10 @@ namespace UAS_Web.tool
|
|
|
IResponseFilter IRequestHandler.GetResourceResponseFilter(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response)
|
|
|
{
|
|
|
var url = new Uri(request.Url);
|
|
|
- if (url.AbsoluteUri.Contains("action"))
|
|
|
+ if (url.AbsoluteUri.ToUpper().Contains(".ACTION"))
|
|
|
{
|
|
|
- Console.WriteLine(request.Url);
|
|
|
var filter = FilterManager.CreateFilter(request.Identifier.ToString()) as MessageFilter;
|
|
|
- string str = System.Text.Encoding.UTF8.GetString(filter.dataAll.ToArray());
|
|
|
- Console.WriteLine("Response" + str);
|
|
|
+ //string str = System.Text.Encoding.UTF8.GetString(filter.dataAll.ToArray());
|
|
|
return filter;
|
|
|
}
|
|
|
return null;
|
|
|
@@ -25,20 +26,17 @@ namespace UAS_Web.tool
|
|
|
|
|
|
void filter_NotifyData(byte[] data)
|
|
|
{
|
|
|
- if (NotifyMsg != null)
|
|
|
- {
|
|
|
- NotifyMsg(data);
|
|
|
- }
|
|
|
+ NotifyMsg?.Invoke(data);
|
|
|
}
|
|
|
|
|
|
void IRequestHandler.OnResourceLoadComplete(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response, UrlRequestStatus status, long receivedContentLength)
|
|
|
{
|
|
|
- if (request.Url.Contains("action"))
|
|
|
+ if (request.Url.ToUpper().Contains(".ACTION"))
|
|
|
{
|
|
|
- Console.WriteLine(request.Url);
|
|
|
var filter = FilterManager.GetFileter(request.Identifier.ToString()) as MessageFilter;
|
|
|
string str = System.Text.Encoding.UTF8.GetString(filter.dataAll.ToArray());
|
|
|
- Console.WriteLine("Request" + str);
|
|
|
+ Console.WriteLine(str);
|
|
|
+ Dictionary<string, object> dic = ToDictionary(str);
|
|
|
filter_NotifyData(filter.dataAll.ToArray());
|
|
|
}
|
|
|
}
|
|
|
@@ -111,5 +109,51 @@ namespace UAS_Web.tool
|
|
|
{
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ public static Dictionary<string, object> ToDictionary(string JsonData)
|
|
|
+ {
|
|
|
+ object Data = null;
|
|
|
+ Dictionary<string, object> Dic = new Dictionary<string, object>();
|
|
|
+ if (JsonData.StartsWith("["))
|
|
|
+ {
|
|
|
+ //如果目标直接就为数组类型,则将会直接输出一个Key为List的List<Dictionary<string, object>>集合
|
|
|
+ //使用示例List<Dictionary<string, object>> ListDic = (List<Dictionary<string, object>>)Dic["List"];
|
|
|
+ List<Dictionary<string, object>> List = new List<Dictionary<string, object>>();
|
|
|
+ MatchCollection ListMatch = Regex.Matches(JsonData, @"{[\s\S]+?}");//使用正则表达式匹配出JSON数组
|
|
|
+ foreach (Match ListItem in ListMatch)
|
|
|
+ {
|
|
|
+ List.Add(ToDictionary(ListItem.ToString()));//递归调用
|
|
|
+ }
|
|
|
+ Data = List;
|
|
|
+ Dic.Add("List", Data);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ MatchCollection Match = Regex.Matches(JsonData, @"""(.+?)"": {0,1}(\[[\s\S]+?\]|null|"".+?""|-{0,1}\d*)");//使用正则表达式匹配出JSON数据中的键与值
|
|
|
+ foreach (Match item in Match)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (item.Groups[2].ToString().StartsWith("["))
|
|
|
+ {
|
|
|
+ //如果目标是数组,将会输出一个Key为当前Json的List<Dictionary<string, object>>集合
|
|
|
+ //使用示例List<Dictionary<string, object>> ListDic = (List<Dictionary<string, object>>)Dic["Json中的Key"];
|
|
|
+ List<Dictionary<string, object>> List = new List<Dictionary<string, object>>();
|
|
|
+ MatchCollection ListMatch = Regex.Matches(item.Groups[2].ToString(), @"{[\s\S]+?}");//使用正则表达式匹配出JSON数组
|
|
|
+ foreach (Match ListItem in ListMatch)
|
|
|
+ {
|
|
|
+ List.Add(ToDictionary(ListItem.ToString()));//递归调用
|
|
|
+ }
|
|
|
+ Data = List;
|
|
|
+ }
|
|
|
+ else if (item.Groups[2].ToString().ToLower() == "null") Data = null;//如果数据为null(字符串类型),直接转换成null
|
|
|
+ else Data = item.Groups[2].ToString(); //数据为数字、字符串中的一类,直接写入
|
|
|
+ Dic.Add(item.Groups[1].ToString(), Data);
|
|
|
+ }
|
|
|
+ catch { }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Dic;
|
|
|
+ }
|
|
|
}
|
|
|
-}
|
|
|
+}
|