2013-12-14 4 views
0

VB.net (owner_id)에서이 코드를 분할하려고합니다. 이것은 데이터 문자열입니다.VB.net 어떻게 분할 할 수 있습니까?

yt.setConfig('DISTILLER_CONFIG', {"signin_url": "https:\/\/accounts.google.com\/ServiceLogin?hl=da\u0026continue=http%3A%2F%2Fwww.youtube.com%2Fsignin%3Faction_handle_signin%3Dtrue%26app%3Ddesktop%26feature%3Dcomments%26hl%3Dda%26next%3D%252Fall_comments%253Fv%253DZNW_uQaYfB0\u0026uilel=3\u0026passive=true\u0026service=youtube", "host_override": "https:\/\/plus.googleapis.com", "query": "http:\/\/www.youtube.com\/watch?v=ZNW_uQaYfB0", "channel_id": "UCe4LM_eKc9ywRmVuBm5pjQg", "first_time_comment_promo": false, "privacy_setting": "PUBLIC", "visible": true, "pinned_activity": null, "page_size": 100, "owner_id": "e4LM_eKc9ywRmVuBm5pjQg", "reauth": false, "video_id": "ZNW_uQaYfB0"}); 

지금까지이 코드를 시도했지만 작동하지 않습니다. 이미 owner_id 문자열이 선언되었습니다.

owner_id = (Split(data, """owner_id"": """)(1).Split("""")(0) 

그러나 작동하지 않습니다.

편집 :

나는이 스크립트에서 분할 할 문자열로 JSON을 선택할 수 있습니다 어떻게 ..?

http://pastebin.com/50bxc83T

+0

이 - 왜 JSON 변환 또는 직 병렬 변환기를 사용하지 (적어도 몇 .NET 용 거기에있다) . – Tim

+0

음, JSON 형식의 HTML 코드뿐 아니라, 그 부분의 데이터가 나눠지기 때문에 그 부분 만 가져 왔습니다. – Anders

답변

0

내가 Regex을 사용하는 것이 좋습니다 것입니다 :

"owner_id": "([\d\w]*)" 

하지만 당신은 정말이 하나의 키/값 쌍을 분석하려는 경우에만 . 더 많이 추출해야한다면 JSON 추출과 일반적인 방식으로 비 직렬화에 대해 생각하고 싶습니다.

근무 예 : 예를 들어 당신이 정규 표현식으로 원하는 하나의 식별자를 포함 할 수 yt.Config(...)처럼 여러 부분이있는 경우

Dim regex As Regex = New Regex("""owner_id"": ""([\d\w]*)""") 
Dim match As Match = regex.Match("...here your string...") 
If match.Success Then 
    Console.WriteLine(match.Groups(1).Value) 
End If 

:

Dim regex As Regex = New Regex("yt.setConfig\('DISTILLER_CONFIG'.*""owner_id"": ""([\d\w]*)""") 
+0

그래, 작동하지만, yt.setConfig (여기 JSON ..)라는 여러 것들이 있기 때문에 그 구체적인 JSON 문자열을 선택하는 방법에 갈 것입니다 전체 HTML 코드와 스레드를 편집하지만, 그래도 고마워! – Anders

+0

@ 앤더스, 제 대답을 업데이트했습니다. 단서를 줄 수 있기를 바랍니다. –

0

이 JSON이다가, 문자열 분할은 그것이 좋은 생각은 아니지만 다음과 같이 Json.NET을 사용하여 JSON을 클래스 객체로 비 직렬화해야합니다.

Public Class DistillerConfigResults 
    Public Property DISTILLER_CONFIG As DistillerConfig 
End Class 

Public Class DistillerConfig 
    Public Property signin_url As String 
    Public Property host_override As String 
    Public Property query As String 
    Public Property signin_url As String 
    Public Property channel_id As String 
    Public Property first_time_comment_promo As Boolean 
    Public Property privacy_setting As String 
    Public Property visible As Boolean 
    Public Property pinned_activity As Object 
    Public Property page_size As Integer 
    Public Property owner_id As String 
    Public Property reauth As Boolean 
    Public Property video_id As String 
End Class 

지금 당신은 실제로이 같은 클래스의 객체로 JSON을 역 직렬화 할 수 있습니다 JSON과 같은

Dim a As DistillerConfigResults = JsonConvert.DeserializeObject(Of DistillerConfigResults)(jsonString) 
관련 문제