dcsimg
Results 1 to 13 of 13

Thread: [RESOLVED] parsing this im stuck i try and try and try

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2014
    Posts
    72

    Resolved [RESOLVED] parsing this im stuck i try and try and try

    ok i have the whole data parsed so its buffered and i have evrything i need to reparse the uid "999999" example 8 digits
    and the username which varys in size but it always looks like this
    "uid":"51879580","away":"0","paid":"E","mic":"1","nickname":"josh1983","color
    there are multiple strings like this in my data i only need the 2 things said above
    so for the nickname i would i think now
    Code:
    but how do i do the array on this situation i = 0 to ubound ????????
    username = split(buffer,"nickname" + 3)(1) 
    username = split (username,"color"-3(0)
    i dunno i get lost on mass parsing bad i need the uid and the nickname but there are say 300 of these string incoming

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,382

    Re: parsing this im stuck i try and try and try

    well first you really shouldn't be splitting on "nickname" ... personally I'm surprised it compiles as you should be getting an error on "nickname" + 3 ... it's probably implicitly converting the 3 to a string "3" and adding it to the string giving you "nickname3" ... bleh...

    First, you should be splitting on the comma... that's what is separating the different items:
    Code:
    Dim items() as string
    items = split(buffer, ",")
    Now Items includes:
    "uid":"51879580"
    "away":"0"
    "paid":"E"
    "mic":"1"
    "nickname":"josh1983"
    So you loop through each one, and split it again, this time on the colon...
    Code:
    Dim items() as string
    items = split(buffer, ",")
    dim a as Integer
    Dim subItems() as string
    For a = 0 to ubound(items)
      subItems = split(items(a), ":")
    MsgBox(subItems(0) & " -- " & subItems(1)
    Next
    As the loop runs, subItems(0) will be the name (uid, away, paid, mic, nickname, etc) and subItems(1) will be the value... so now you can get to the uid and nickname:
    Code:
    Dim items() as string
    dim a as Integer
    dim uid as string
    dim nickname as string
    items = split(buffer, ",")
    Dim subItems() as string
    For a = 0 to ubound(items)
      subItems = split(items(a), ":")
      If subItems(0) = "uid" then
        uid = subitems(1)
      elseif subItems(0) = "nickname" then
        nickname = subItems(1)
      End If
    Next
    At the end of that, the variables uid and nickname hold their values from the buffer.


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2014
    Posts
    72

    Re: parsing this im stuck i try and try and try

    ok that will work if the only string are as the string i posted above maybe i said it all wrong ok i have the list parsed but it contains alot of other stuff besides that string i posted but i only need the info between uid thing and color then after i parse all that out i will have a buffer of just the string i posted above and be able to do as you posted ... the problem is before that the data contains nickname and ect but the only parts that are correct are the "uid":"82843660","away":"0","paid":"E","mic":"1","nickname":"kiwi-dancer","color"

    that uid is that nicknamea uid
    the data looks like this


    {"uid":"82843660","away":"0","paid":"E","mic":"1","nickname":"kiwi-dancer","color":"153000255","admin":"0","vg":"5","group_id":"25997","pub":"N","ct":"2"},"javaClass": "java.util.HashMap"},"req":0,"gr":0,"primary_image":null},{"location":null,"vg":1,"ngr":0,"primary_e xists":false,"paid":"E","age":0,"gender":null,"has_profile":false,"user_id":89708268,"top":0,"birth_ date":0,"nickname":"kiwi_dancer","group_id":25997,"pub":"N","ct":0,"country":null,"away":0,"mic":1," profile_banned":0,"color":"153000255","admin":0,"javaClass":"com..chat.common.GroupMember","attribut es":{"map":{"uid":"89708268","away":"0","paid":"E","mic":"1","nickname":"kiwi_dancer","color":"15300 0255","admin":"0","vg":"1","group_id":"25997","pub":"N","ct":"11"},"javaClass":"java.util.HashMap"}, "req":0,"gr":0,"primary_image":null},{"location":null,"vg":0,"ngr":0,"primary_exists":false,"paid":" N","age":0,"gender":null,"has_profile":false,"user_id":98502653,"top":0,"birth_date":0,"nickname":"m eanie

    thats what my parsed roomlist looks like now
    now that i posted this i see this is what i need out of buffer multiple time as diff user_id and nicknames are in it multiple times

    "user_id":89708268,"top":0,"birth_date":0,"nickname":"kiwi_dancer","group_id"

    the data between user_id": & group_id"

    then after i get all these parsed out i could use the , split and get the data needed i think i said this right

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2014
    Posts
    72

    Re: parsing this im stuck i try and try and try

    cause see it has the nickname sever times so i have to get the strings out first and the strings are as shown here
    "user_id":89708268,"top":0,"birth_date":0,"nickname":"kiwi_dancer","group_id

    i need to get all buffer data between the user_id:" and the group_id and then parse out what i need

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2014
    Posts
    72

    Re: parsing this im stuck i try and try and try

    Code:
    Dim uids() As String
    uids = Split(buff, "user_id" & Chr(&H22) & ":")(1)
    uids = Split(uids, Chr(&H22) & "," & Chr(&H22) & "group_id")(0)
    
    For x = 0 To UBound(uids)
        Debug.Print uids(x)
      
        Next
    this is what i tried to get those strings out and after i ghet these i can prob get it

  6. #6
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,282

    Re: parsing this im stuck i try and try and try

    If you only need uid and nickname, I wouldn't use split. Just use Instr to find where each start, and instr to find where each end, and mid$ to pull out the parts.
    Along the lines (assume you have your string in buf$):
    Code:
    s = instr(buf$,"{""uid"":""") + 8 'look for where {"uid":" starts and add 8 to get to begining of uid number
    do until s = 0
      e = instr(s,buf$, """")   'find the next " after that
      uid = mid$(buf$,s,e-s) 'uid equal to the mid$ between s and e
      s = instr(e,buf$,"nickname""") + 11
      e = instr(s,buf$,"""") 'find the next " after that
      nickname = mid$(buf$,s,e-s) 'extract nickname
      s = instr(e,buf$,"{""uid"":""") + 8 'look for where next {"uid":" starts and add 8 to get to begining of uid number
    loop
    I just typed it in so there could be mistakes. Step through the code in the IDE and watch how it parses and see that the offsets are correct and it is pulling the correct substrings.

  7. #7
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,346

    Re: parsing this im stuck i try and try and try

    How about this? Just add List1 to a form then add this code.

    Code:
    Option Explicit
    
    Private Sub Form_Load()
    Dim item As Variant
    Dim items() As String
    Dim a As Integer
    Dim uid As String
    Dim nickname As String
    Dim buffer As String
    buffer = "uid:82843660,away:0,paid:E,mic:1,nickname:kiwi-dancer,color:153000255,admin:0,vg:5,group_id:25997,pub:N,ct:2},javaClass: java.util.HashMap},req:0,gr:0,primary_image:null},{location:null,vg:1,ngr:0,primary_e xists:false,paid:E,age:0,gender:null,has_profile:false,user_id:89708268,top:0,birth_ date:0,nickname:kiwi_dancer,group_id:25997,pub:N,ct:0,country:null,away:0,mic:1, profile_banned:0,color:153000255,admin:0,javaClass:com..chat.common.GroupMember,attribut es:{map:{uid:89708268,away:0,paid:E,mic:1,nickname:kiwi_dancer,color:15300 0255,admin:0,vg:1,group_id:25997,pub:N,ct:11},javaClass:java.util.HashMap}, req:0,gr:0,primary_image:null},{location:null,vg:0,ngr:0,primary_exists:false,paid: N,age:0,gender:null,has_profile:false,user_id:98502653,top:0,birth_date:0,nickname:m eanie"
    items = Split(buffer, ",")
    Dim subItems() As String
    For a = 0 To UBound(items)
      subItems = Split(items(a), ":")
      If subItems(0) = "uid" Then
        uid = subItems(1)
      ElseIf subItems(0) = "nickname" Then
        nickname = subItems(1)
      End If
          For Each item In subItems()
            List1.AddItem (item)
          Next
    Next
    
    End Sub
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Aug 2014
    Posts
    72

    Re: parsing this im stuck i try and try and try

    ,"admin":0,"javaClass":"com..chat.common.GroupMember","attributes":{"map":{"uid":"3335345","away":"0 ","paid":"E","mic":"1","nickname":"tamjamus","color":"000128000","admin":"0","group_id":"25997","pub ":"N","ct":"2"},"javaClass":"java.util.HashMap"},"req":0,"gr":0,"primary_image":null},{"location":nu ll,"vg":0,"ngr":0,"primary_exists":false,"paid":"E","age":0,"gender":null,"has_profile":false,"user_ id":51879580,"top":0,"birth_date":0,"nickname":"wujenone","group_id":25997,"pub":"N","ct":0,"country ":null,"away":0,"mic":1,"profile_banned":0,"color":"000128000","admin":1,"javaClass":"com..chat.comm on.GroupMember","attributes":{"map":{"uid":"51879580","away":"0","paid":"E","mic":"1","nickname":"wu jenone","color":"000128000","admin":"1","group_id":"25997","pub":"N","ct":"2"},"javaClass":"java.uti l.HashMap"},"req":0,"gr":0,"primary_image":null},{"location":null,"vg":0,"ngr":0,"primary_exists":fa lse,"paid":"E","age":0,"gender":null,"has_profile":false,"user_id":59709835,"top":0,"birth_date":0," nickname":"blackapple","group_id":25997,"pub":"N","ct":0,"country":null,"away":0,"mic":1,"profile_ba nned":0,"color":"000128000","admin":0,"javaClass":"com..chat.common.GroupMember","attributes":{"map" :{"uid":"59709835","away":"0","paid":"E","mic":"1","nickname":"blackapple","color":"000128000","admi n":"0","group_id":"25997","pub":"N","ct":"2"},"javaClass":"java.util.HashMap"},"req":0,"gr":0,"prima ry_image":null},{"location":null,"vg":5,"ngr":0,"primary_exists":false,"paid":"E","age":0,"gender":n ull,"has_profile":false,"user_id":82843660,"top":0,"birth_date":0,"nickname":"kiwi-dancer","group_id":25997,"pub":"N","ct":0,"country":null,"away":0,"mic":1,"profile_banned":0,"color" :"153000255","admin":0,"javaClass":"com..chat.common.GroupMember","attributes":{"map":{"uid":"828436 60","away":"0","paid":"E","mic":"1","nickname":"kiwi-dancer","color":"153000255","admin":"0","vg":"5","group_id":"25997","pub":"N","ct":"2"},"javaClass": "java.util.HashMap"},"req":0,"gr":0,"primary_image":null},{"location":null,"vg":1,"ngr":0,"primary_e xists":false,"paid":"E","age":0,"gender":null,"has_profile":false,"user_id":89708268,"top":0,"birth_ date":0,"nickname":"kiwi_dancer","group_id":25997,"pub":"N","ct":0,"country":null,"away":0,"mic":1," profile_banned":0,"color":"153000255","admin":0,"javaClass":"com..chat.common.GroupMember","attribut es":{"map":{"uid":"89708268","away":"0","paid":"E","mic":"1","nickname":"kiwi_dancer","color":"15300 0255","admin":"0","vg":"1","group_id":"25997","pub":"N","ct":"11"},"javaClass":"java.util.HashMap"}, "req":0,"gr":0,"primary_image":null},{"location":null,"vg":0,"ngr":0,"primary_exists":false,"paid":" N","age":0,"gender":null,"has_profile":false,"user_id":98502653,"top":0,"birth_date":0,"nickname":"m eanie guy","group_id":25997,"pub":"N","ct":0,"country":null,"away":0,"mic":1,"profile_banned":0,"color":"



    is there a way i can pull the strings between user_id and group_id out of this data there is like 5 of these strings

  9. #9
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,382

    Re: parsing this im stuck i try and try and try

    Ok... hold on... that looks like a JSON string...
    which then makes me wonder if there is a JSON library for VB6... turns out there is... at least according to this post - http://stackoverflow.com/questions/2...er-for-vb6-vba

    And a bit closer to home, there's this post in our own codebank - http://www.vbforums.com/showthread.p...rser-Generator

    And this one... http://www.ediy.co.nz/vbjson-json-pa...xidc55680.html


    That's probably what I'd look into next... otherwise I think you're just going to be asking for trouble trying to parse through all that by "hand".


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  10. #10
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,282

    Re: parsing this im stuck i try and try and try

    Quote Originally Posted by josh1983 View Post
    ...
    is there a way i can pull the strings between user_id and group_id out of this data there is like 5 of these strings
    Either check out the JSON links provided, or the code I posted should be easily modified to do it.
    You just use Instr to look for user_id and note the position, and then look for group_id and note the position and use mid$ to pull out the substring between those two positions.
    The great thing about VB is that you can step through the code and adjust the offset, and change the variables, or set the next line to be executed, so can do the same line over and over until it is right, then go on to the next line. A couple of minutes stepping through the code and adjusting the code as you parse and reexecuting the same line to see if you fixed it allows you to interactively parse and adjust the code as you go so you don't waste a lot of time restarting from the begining each time.

    When parsing something new, I rarely put all the parsing code in at the begining. I just add code to open the file and read a line and break.
    I can look at the line read, add a line of code to parse the particular thing I need, then step that line, verify it did what I wanted, then decide what I want to do next, add a line, step, verify. If it didn't do what I expected, fix it, set the "Next Line" to be the line fixed, and step it again to see if it worked that time. You can keep modifying and restepping that line until it is correct and then move on.
    Being able to modify code as you run it is one of the biggest time saving benefits of VB over most any other language.

  11. #11
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,346

    Re: parsing this im stuck i try and try and try

    Quote Originally Posted by techgnome View Post
    Ok... hold on... that looks like a JSON string...
    It would have been helpful if the original poster had included which, technology it was in the first post.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Aug 2014
    Posts
    72

    there is no way i can parse ubound data between to delimeters?

    so there is no way to parse incoming data with 2 dilimeters like this kinda

    Code:
    Dim udats() As String, udat As String, x As Integer
    udat = Split(roomlist, "user_id" & Chr(&H22) & ":")(1)
    udats = Split(udat, Chr(&H22) & "," & Chr(&H22) & "group_id")(0)
    For x = 0 To UBound(udats)
        Debug.Print udats(x)
      
        Next
    i know this erors but this idea somthing to this effect which if this worked i would have all the strings i am trying to get out of this buffered data then i could easly parse the need info out

  13. #13
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,382

    Re: there is no way i can parse ubound data between to delimeters?

    Quote Originally Posted by Nightwalker83 View Post
    It would have been helpful if the original poster had included which, technology it was in the first post.
    Pfffft! This ain't your first trip to the rodeo... you know that's a common occurrence here... par for the course.


    Quote Originally Posted by josh1983 View Post
    so there is no way to parse incoming data with 2 dilimeters like this kinda

    Code:
    Dim udats() As String, udat As String, x As Integer
    udat = Split(roomlist, "user_id" & Chr(&H22) & ":")(1)
    udats = Split(udat, Chr(&H22) & "," & Chr(&H22) & "group_id")(0)
    For x = 0 To UBound(udats)
        Debug.Print udats(x)
      
        Next
    i know this erors but this idea somthing to this effect which if this worked i would have all the strings i am trying to get out of this buffered data then i could easly parse the need info out
    No there isn't. But as has been pointed out, what you appear to have is a JSON string. Which is a well-known format and, when used with a parser, is easily dealt with. The parser will take care of processing the string and breaking up the pieces, and returning to you an object that is a class which represents the data. From there you can then get the properties that you want, and BAM! Bob's your uncle.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width