[Tween-svn] [1519] JSON解析時のエラー処理追加

Zurück zum Archiv-Index

svnno****@sourc***** svnno****@sourc*****
2011年 4月 26日 (火) 21:31:44 JST


Revision: 1519
          http://sourceforge.jp/projects/tween/svn/view?view=rev&revision=1519
Author:   syo68k
Date:     2011-04-26 21:31:44 +0900 (Tue, 26 Apr 2011)

Log Message:
-----------
JSON解析時のエラー処理追加

Modified Paths:
--------------
    trunk/Tween/Google.vb
    trunk/Tween/Thumbnail.vb


-------------- next part --------------
Modified: trunk/Tween/Google.vb
===================================================================
--- trunk/Tween/Google.vb	2011-04-26 12:21:53 UTC (rev 1518)
+++ trunk/Tween/Google.vb	2011-04-26 12:31:44 UTC (rev 1519)
@@ -196,8 +196,15 @@
         Dim content As String = ""
         If http.GetData(apiurl, headers, content) Then
             Dim serializer As New DataContractJsonSerializer(GetType(TranslateResponse))
-            Dim res As TranslateResponse = CreateDataFromJson(Of TranslateResponse)(content)
+            Dim res As TranslateResponse
 
+            Try
+                res = CreateDataFromJson(Of TranslateResponse)(content)
+            Catch ex As Exception
+                ErrMsg = "Err:Invalid JSON"
+                Return False
+            End Try
+
             If res.ResponseData Is Nothing Then
                 ErrMsg = "Err:" + res.ResponseDetails
                 Return False
@@ -221,8 +228,12 @@
         Dim content As String = ""
         If http.GetData(apiurl, headers, content) Then
             Dim serializer As New DataContractJsonSerializer(GetType(LanguageDetectResponse))
-            Dim res As LanguageDetectResponse = CreateDataFromJson(Of LanguageDetectResponse)(content)
-            Return res.ResponseData.Language
+            Try
+                Dim res As LanguageDetectResponse = CreateDataFromJson(Of LanguageDetectResponse)(content)
+                Return res.ResponseData.Language
+            Catch ex As Exception
+                Return ""
+            End Try
         End If
         Return ""
     End Function

Modified: trunk/Tween/Thumbnail.vb
===================================================================
--- trunk/Tween/Thumbnail.vb	2011-04-26 12:21:53 UTC (rev 1518)
+++ trunk/Tween/Thumbnail.vb	2011-04-26 12:31:44 UTC (rev 1519)
@@ -2259,8 +2259,14 @@
         If (New HttpVarious).GetData(apiurl, Nothing, src, 0, args.errmsg, GetUserAgentString()) Then
             Dim sb As New StringBuilder
             Dim serializer As New DataContractJsonSerializer(GetType(PicPlzDataModel.ResultData))
-            Dim res As PicPlzDataModel.ResultData = CreateDataFromJson(Of PicPlzDataModel.ResultData)(src)
+            Dim res As PicPlzDataModel.ResultData
 
+            Try
+                res = CreateDataFromJson(Of PicPlzDataModel.ResultData)(src)
+            Catch ex As Exception
+                Return False
+            End Try
+
             If res.Result = "ok" Then
                 Try
                     imgurl = res.Value.Pics(0).PicFiles.Pic320rh.ImgUrl



Tween-svn メーリングリストの案内
Zurück zum Archiv-Index