苏州三木软件科技有限公司

 找回密码
 立即注册
搜索
热搜: 活动
查看: 356|回复: 2

困扰几天JSON解析报错,请高手们支招!

[复制链接]

30

主题

45

帖子

191

积分

注册会员

Rank: 2

积分
191
发表于 2024-4-7 13:46:20 | 显示全部楼层 |阅读模式

报错内容中manufacturer_name,这个字段我并没有解析,且每次解析的数据报错的数据条不在同一位置。有时是1100+条数据报错,有时1300+条数据报错,有时又是1500+条位置报错。
数据来源:https://api.fda.gov/drug/event.json?search=receivedate:[20220103+TO+20220103]&limit=1000&skip=1000,这里的1000表示数据条数和取数位置
报错内容如下:


详细的错误信息如下:

(Inner Exception)
当前软件版本:2024.4.2.1
当前授权版本:Published
记录时间:         2024/4/7 13:30:02
机器名称:          iZ16k48jasthnbZ
IP地址:            172.31.6.198
当前用户:          IZ16K48JASTHNBZ\Administrator

应用程序:    SanMuGrid.exe
程序位置:     file:///C:/myProgramFiles/drugoptserverp/SanMuGrid.exe
程序全名:    SanMuGrid, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
程序版本:      1.0.0.0
程序创建时间:   2024/4/2 9:59:40

日志ID:      20240407133002748
异常来源:      Newtonsoft.Json
异常类型:        Newtonsoft.Json.JsonReaderException
异常信息:     After parsing a value an unexpected character was encountered: D. Path 'results[18].patient.drug[2].openfda.manufacturer_name[17]', line 24812, position 66.
引发异常的方法位置: ParsePostValue

---- Stack Trace ----
   Newtonsoft.Json.JsonTextReader.ParsePostValue(ignoreComments As Boolean)
       SanMuGrid.exe: N 00587
   Newtonsoft.Json.JsonTextReader.Read()
       SanMuGrid.exe: N 00131
   Newtonsoft.Json.Linq.JContainer.ReadContentFrom(r As JsonReader, settings As JsonLoadSettings)
       SanMuGrid.exe: N 00763
   Newtonsoft.Json.Linq.JContainer.ReadTokenFrom(reader As JsonReader, options As JsonLoadSettings)
       SanMuGrid.exe: N 00051
   Newtonsoft.Json.Linq.JObject.Load(reader As JsonReader, settings As JsonLoadSettings)
       SanMuGrid.exe: N 00180
   Newtonsoft.Json.Linq.JObject.Parse(json As String, settings As JsonLoadSettings)
       SanMuGrid.exe: N 00084
   sanMuSoft.FunctionsRunTime.UserCodesVB.AB9cc7a06ed7b54bcf91b06b260d13fb52(Args As Object[])
       SanMuGrid.exe: N 01054


回复

使用道具 举报

22

主题

296

帖子

1870

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1870
QQ
发表于 2024-4-7 13:57:31 | 显示全部楼层
报错信息显示:在解析路径: 'results[18].patient.drug[2].openfda.manufacturer_name[17]'时,遇到意外字符。
你需要在出错时,将相应的Json文本保存到日志中,然后定位到相应的路径看看,到底这个路径上的文本有什么异常。这个错误并不是你访问某个节点触发的异常,而是解析时就发生的异常。JObject.Parse(strJson)时发生的。
回复

使用道具 举报

22

主题

296

帖子

1870

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1870
QQ
发表于 2024-4-7 14:04:48 | 显示全部楼层
你试试下面的代码能不能帮你度过难关
  1. Dim joLoading As New JsonLoadSettings
  2. joLoading.CommentHandling=CommentHandling.Ignore
  3. joLoading.LineInfoHandling=LineInfoHandling.Ignore
  4. JObject.Parse("json字符串",joLoading)
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|苏州三木软件科技有限公司 ( 苏ICP备2022038390号 )

苏公网安备 32058502010732号

GMT+8, 2024-7-5 04:11 , Processed in 0.086208 second(s), 22 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表