Foxtable(狐表)用户栏目专家坐堂 → 解析webservice返回的xml


  共有3875人关注过本帖树形打印复制链接

主题:解析webservice返回的xml

帅哥哟,离线,有人找我吗?
有点蓝
  11楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:107754 积分:548109 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2017/5/10 17:27:00 [只看该作者]

xo("NewDataSet")("ds")("PATIENTNO")

 回到顶部
帅哥哟,离线,有人找我吗?
ycwk
  12楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1218 积分:8451 威望:0 精华:0 注册:2016/2/2 21:52:00
  发帖心情 Post By:2017/5/10 17:28:00 [只看该作者]

If xo("NewDataSet")("ds")  Is Jarray Then
            msgbox("这个是数组")
         Else
            msgbox("这不是数组")
         End If

报错:  
---------------------------
错误
---------------------------
编译错误:“Jarray”是一个类型,不能用作表达式。



错误代码:If xo("NewDataSet")("ds")  Is Jarray Then
---------------------------
确定   
---------------------------


 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  13楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:107754 积分:548109 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2017/5/10 17:43:00 [只看该作者]

被和谐了

if Typeof xo("NewDataSet")("ds")  Is Jarray then
这个是数组
else
不是数组
end if

 回到顶部
帅哥哟,离线,有人找我吗?
ycwk
  14楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1218 积分:8451 威望:0 精华:0 注册:2016/2/2 21:52:00
  发帖心情 Post By:2017/5/10 18:13:00 [只看该作者]

遇到一种特殊情况的xml,解析不了


图片点击可在新窗口打开查看此主题相关图片如下:1.png
图片点击可在新窗口打开查看



怎么处理?


我的代码如下:
   Dim str4 As String = "http://10.27.*.*:8085/Service.asmx/Query?queryxml=<root><queryid>QueryReportDetail</queryid><args1>" & str_seqno & "</args1></root>"      
    Dim hc As New HttpClient(str4)
    Dim ret As String = hc.GetData()      
    Dim xo As XObject = XObject.Parse(HTMLDecode(ret))


 If Typeof xo("NewDataSet")("ds")  Is jarray Then          '如果是数组    即 有多行结果用如下代码.    
     With wb.AddTable("","Table1")
        .head.AddRow("项目名称","检查结果","范围","标志","单位") '主表的表头
         For Each ds As JToken In  xo("NewDataSet")("ds")    
          ' .body.AddRow( CStr(ds("LISITEMNAME")), CStr(ds("RESULT")),CStr(ds("RANGE")),CStr(ds("FLAG")),CStr(ds("UNIT")) )      
           .body.AddRow( ds("LISITEMNAME"),ds("RESULT"),ds("RANGE"),ds("FLAG"),ds("UNIT"))      
         Next
    End With 
 Else           '如果不是数组,即呆有一行结果.
    With wb.AddTable("","Table1")
        .head.AddRow("项目名称","检查结果","范围","标志","单位") '主表的表头
        ' For Each ds As JToken In  xo("NewDataSet")("ds")    
          ' .body.AddRow( CStr(ds("LISITEMNAME")), CStr(ds("RESULT")),CStr(ds("RANGE")),CStr(ds("FLAG")),CStr(ds("UNIT")) )      ' '注意如果主表只有一项并没有明细,则这里会报错
           .body.AddRow( xo("NewDataSet")("ds")("LISITEMNAME"), xo("NewDataSet")("ds")("RESULT"),xo("NewDataSet")("ds")("RANGE"),xo("NewDataSet")("ds")("FLAG"),xo("NewDataSet")("ds")("UNIT"))      
        ' Next
    End With 
 End If 

[此贴子已经被作者于2017/5/10 18:17:18编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
有点色
  15楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:13837 积分:69650 威望:0 精华:0 注册:2016/11/1 14:42:00
  发帖心情 Post By:2017/5/10 20:14:00 [只看该作者]

 把你获取到的字符保存在txt里面上传上来测试。

 回到顶部
帅哥哟,离线,有人找我吗?
有点色
  16楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:13837 积分:69650 威望:0 精华:0 注册:2016/11/1 14:42:00
  发帖心情 Post By:2017/5/10 20:16:00 [只看该作者]

 不是可以判断是否为数组?

 


If Typeof xo("NewDataSet")("ds")  Is Jarray Then '多行数据

Else    '一行数据

End If

 回到顶部
帅哥哟,离线,有人找我吗?
ycwk
  17楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1218 积分:8451 威望:0 精华:0 注册:2016/2/2 21:52:00
  发帖心情 Post By:2017/5/11 9:04:00 [只看该作者]

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:xml.txt


遇到中间的  <UNIT xml:space="preserve">  解析时就报错

---------------------------
版本:2017.4.22.1
---------------------------
代码执行出错,错误信息:



System.ArgumentException: Can not convert Object to String.

   在 Newtonsoft.Json.Linq.JToken.op_Explicit(JToken value)

   在 UserCode.Test()
---------------------------
确定   
---------------------------



用以下的代码:

 Dim str4 As String = "http://10.27.1.1:8085/Service.asmx/Query?queryxml=<root><queryid>QueryReportDetail</queryid><args1>59711</args1></root>"      
    Dim hc As New HttpClient(str4)
    Dim ret As String = hc.GetData()      
    Dim xo As XObject = XObject.Parse(HTMLDecode(ret))

     msgbox(xo.ToString)
    ' With wb.AddTable("","Table1")
     '   .head.AddRow("项目名称","检查结果","范围","标志") '主表的表头
         For Each ds As JToken In  xo("NewDataSet")("ds")    
          '  output.show( ds("LISITEMNAME"), ds("RESULT"),ds("RANGE"),CStr(ds("FLAG") )      
  msgbox(0) 
           output.show( ds("RANGE")) 
  msgbox(1)
            output.show( ds("FLAG")) 
msgbox(2)
            output.show( ds("LISITEMNAME")) 
msgbox(3)
            output.show(ds("RESULT")) 
msgbox(4) 
            output.show(ds("UNIT"))    
   msgbox(5)    
         Next


 回到顶部
帅哥哟,离线,有人找我吗?
有点色
  18楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:13837 积分:69650 威望:0 精华:0 注册:2016/11/1 14:42:00
  发帖心情 Post By:2017/5/11 10:21:00 [只看该作者]

Dim ret As String = FileSys.ReadAllText("g:\xml.txt", encoding.default)
Dim xo As XObject = XObject.Parse(HTMLDecode(ret))

For Each ds As JToken In  xo("NewDataSet")("ds")
    '  output.show( ds("LISITEMNAME"), ds("RESULT"),ds("RANGE"),CStr(ds("FLAG") )
   
    output.show( ds("RANGE"))
   
    output.show( ds("FLAG"))
   
    output.show( ds("LISITEMNAME"))
   
    output.show(ds("RESULT"))
    If Typeof ds("UNIT") Is jvalue Then
        output.show(ds("UNIT"))
    Else
        msgbox(ds("UNIT").Tostring)
    End If

   
Next


 回到顶部
帅哥哟,离线,有人找我吗?
ycwk
  19楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1218 积分:8451 威望:0 精华:0 注册:2016/2/2 21:52:00
  发帖心情 Post By:2017/5/11 10:55:00 [只看该作者]

用下面这段代码,虽然不报错但仍然有下面的异常字符出来.


尿亚硝酸盐--N{          
  "@xml:space": "preserve",
  "#significant-whitespace": "        "
}



Dim str4 As String = "http://10.27.1.1:8085/Service.asmx/Query?queryxml=<root><queryid>QueryReportDetail</queryid><args1>59711</args1></root>"      
    Dim hc As New HttpClient(str4)
    Dim ret As String = hc.GetData()      
    Dim xo As XObject = XObject.Parse(HTMLDecode(ret))


 If Typeof xo("NewDataSet")("ds")  Is jarray Then          '如果是数组    即 有多行结果用如下代码.    
msgbox(0)
  '   With wb.AddTable("","Table1")
       ' .head.AddRow("项目名称","检查结果","范围","标志","单位") '主表的表头
         For Each ds As JToken In  xo("NewDataSet")("ds")    
          ' .body.AddRow( CStr(ds("LISITEMNAME")), CStr(ds("RESULT")),CStr(ds("RANGE")),CStr(ds("FLAG")),CStr(ds("UNIT")) )    
           If Typeof ds("UNIT") Is jvalue Then
msgbox(00)
              ' output.show(ds("LISITEMNAME"),ds("RESULT"),ds("RANGE"),ds("FLAG"),ds("UNIT"))      
                Output.show(cstr(ds("LISITEMNAME")) & cstr(ds("RESULT")) & cstr(ds("RANGE")) & cstr(ds("FLAG")) & cstr(ds("UNIT")))
           Else
msgbox(01)
                Output.show(cstr(ds("LISITEMNAME")) & cstr(ds("RESULT")) & cstr(ds("RANGE")) & cstr(ds("FLAG")) & cstr(ds("UNIT").ToString))         '过滤掉中间的  <UNIT xml:space="preserve">  解析时就报错
           End If         
         Next
   ' End With 
 Else           '如果不是数组,即呆有一行结果.
msgbox(1)
   ' With wb.AddTable("","Table1")
      '  .head.AddRow("项目名称","检查结果","范围","标志","单位") '主表的表头
        ' For Each ds As JToken In  xo("NewDataSet")("ds")    
          ' .body.AddRow( CStr(ds("LISITEMNAME")), CStr(ds("RESULT")),CStr(ds("RANGE")),CStr(ds("FLAG")),CStr(ds("UNIT")) )      
            If Typeof xo("NewDataSet")("ds")("UNIT") Is jvalue Then
msgbox(10)
          output.Show(cstr(xo("NewDataSet")("ds")("LISITEMNAME")) &  cstr(xo("NewDataSet")("ds")("RESULT")) & cstr(xo("NewDataSet")("ds")("RANGE")) & cstr(xo("NewDataSet")("ds")("FLAG")) & cstr(xo("NewDataSet")("ds")("UNIT").ToString))    
           Else
msgbox(11)
          output.Show(cstr(xo("NewDataSet")("ds")("LISITEMNAME")) &  cstr(xo("NewDataSet")("ds")("RESULT")) & cstr(xo("NewDataSet")("ds")("RANGE")) & cstr(xo("NewDataSet")("ds")("FLAG")) & cstr(xo("NewDataSet")("ds")("UNIT")))        
           End If 

 End If 

 回到顶部
帅哥哟,离线,有人找我吗?
有点色
  20楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:13837 积分:69650 威望:0 精华:0 注册:2016/11/1 14:42:00
  发帖心情 Post By:2017/5/11 10:58:00 [只看该作者]

你不是可以不显示?红色代码不写就好了啊

 

    If Typeof ds("UNIT") Is jvalue Then
        output.show(ds("UNIT"))
    Else
        msgbox(ds("UNIT").Tostring)
    End If


 回到顶部
总数 26 上一页 1 2 3 下一页