dcsimg
Page 4 of 4 FirstFirst 1234
Results 121 to 132 of 132

Thread: VB6 - JsonBag, Another JSON Parser/Generator

  1. #121

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,969

    Re: VB6 - JsonBag, Another JSON Parser/Generator

    First, be sure to note that my TreeView example is incomplete.

    You have to consider that both property name values and string type data values can contain characters that are incompatible with an ANSI TreeView control. Any characters outside the printable 7-bit ASCII range can be problematic, even if some ANSI printables might come out acceptably depending on the locale settings when your program gets run.

    So you really need to escape funky characters or at least zap them to ? or some other place-filler symbol.


    As for color-coding formatted JSON goes, no I do not have anything on hand for that.

    But it seems simple enough to copy and hack JsonBag's Property Get JSON() serialization to create a Property Get JSONRTF() or a Property Get JSONHTML() that returns marked up JSON with colors. It is just a matter of doing the necessary busy work.

  2. #122
    PowerPoster
    Join Date
    Feb 2017
    Posts
    2,213

    Re: VB6 - JsonBag, Another JSON Parser/Generator

    Quote Originally Posted by k_zeon View Post
    I think a Rich TextBox could be more appropriate for this.

  3. #123
    Addicted Member
    Join Date
    Nov 2011
    Posts
    155

    Re: VB6 - JsonBag, Another JSON Parser/Generator

    Quote Originally Posted by dilettante View Post
    First, be sure to note that my TreeView example is incomplete.

    You have to consider that both property name values and string type data values can contain characters that are incompatible with an ANSI TreeView control. Any characters outside the printable 7-bit ASCII range can be problematic, even if some ANSI printables might come out acceptably depending on the locale settings when your program gets run.

    So you really need to escape funky characters or at least zap them to ? or some other place-filler symbol.


    As for color-coding formatted JSON goes, no I do not have anything on hand for that.

    But it seems simple enough to copy and hack JsonBag's Property Get JSON() serialization to create a Property Get JSONRTF() or a Property Get JSONHTML() that returns marked up JSON with colors. It is just a matter of doing the necessary busy work.
    Hi dilettante. tks for reply. I will look in to hacking the JSON() and see if poss to create JSONRTF.

  4. #124
    Addicted Member
    Join Date
    Nov 2011
    Posts
    155

    Re: VB6 - JsonBag, Another JSON Parser/Generator

    Quote Originally Posted by Eduardo- View Post
    I think a Rich TextBox could be more appropriate for this.
    Hi Eduardo. Yes i have used this before to display VB6 code and works very well. However i dont know how to modify the existing code to take care of Json / Javascript
    as above post , i will see about modifying the JsonBag to create a JsonRTF as that would be quite good as i use JsonBag to show in a textbox and nicely spaced out.
    maybe i can take it a step closer to use a RichtextBox to display data. would be a good addition to JsonBag.

    If i try to create a JsonRTF would i create a string that contains the Json and the richtext code and then apply to the richtextbox
    or once text is on the Richtextbox loop through and colour code the text accordingly.

    I am thinking option one as it goes through the serailisation to add richtext formatting as we go.

    what do you think

    thanks
    Last edited by k_zeon; Mar 6th, 2019 at 08:53 AM.

  5. #125
    New Member
    Join Date
    Apr 2019
    Posts
    1

    Re: VB6 - JsonBag, Another JSON Parser/Generator

    Hi
    I am using JSONBag 2.5 with VB6 to try and create a series of Json messages. I have managed to write working procedures for all the messages bar one. This one needs an array within it. I don't seem to be able to grasp the way to contruct this code. Can somebody give me a few pointers?
    So the complete message should look like this:

    {
    "MaintenanceType": "Preventive",
    "MaintenanceOrderNumber": "MO676578576",
    "MaintenanceJobCode": "MNT113334",
    "Tasks": [
    {
    "Task": "Changed hydraulic fluid in resovoir 1",
    "TaskId": "HYD233432432",
    "Operator": {
    "OperatorIdentifier": "BADGE489435",
    "ActorType": "Human",
    "LastName": "Smith",
    "FirstName": "Joseph",
    "LoginName": "joseph.smith@abcdrepairs.com"
    },
    "ManHoursConsumed": 0.75
    },
    {
    "Task": "Checked torque on main mount bolts",
    "TaskId": "CHK3432434",
    "Operator": {
    "OperatorIdentifier": "UID235434324",
    "ActorType": "Human",
    "LastName": "Smith",
    "FirstName": "Joseph",
    "LoginName": "joseph.smith@abcdrepairs.com"
    },
    "ManHoursConsumed": 0.25
    }
    ]
    }
    and my code looks like this:

    Code:
    '---------------------------------------------------------------------------------------
    ' Method : CFXMaintenancePerformed
    ' Author : Simon Smith
    ' Date   : 07/12/2016
    ' Purpose: Create CFX.ResourcePerformance.MaintenancePerformed message
    ' Updated:  13/12/2018
    '---------------------------------------------------------------------------------------
    Public Sub CFXMaintenancePerformed()
    
        CFXEnvelope                                             ' Add envelope data
        With JB
            ![MessageName] = "CFX.ResourcePerformance.MaintenancePerformed"
            With .AddNewObject("MessageBody")                     ' Add Message Body specifics
                .Item("MaintenanceType") = "Preventive"
                .Item("MaintenanceOrderNumber") = "MO676578576"
                .Item("MaintenanceJobCode") = "MNT113334"
                With .AddNewArray("Tasks")
                    With .AddNewArray()
                        .Item("Task") = "Changed hydraulic fluid in resovoir 1"
                        .Item("TaskId") = "HYD233432432"
                        With .AddNewObject("Operator")
                            .Item("OperatorIdentifier") = "BADGE489435"
                            .Item("ActorType") = "Human"
                            .Item("LastName") = "Smith"
                            .Item("FirstName") = "Joseph"
                            .Item("LoginName") = "joseph.smith@abcdrepairs.com"
                        End With
                        .Item("ManHoursConsumed") = 0.75
                    End With
                    With .AddNewArray()
                        .Item("Task") = "Checked torque on main mount bolts"
                        .Item("TaskId") = "CHK3432434"
                        With .AddNewObject("Operator")
                            .Item("OperatorIdentifier") = "UID235434324"
                            .Item("ActorType") = "Human"
                            .Item("LastName") = "Smith"
                            .Item("FirstName") = "Joseph"
                            .Item("LoginName") = "joseph.smith@abcdrepairs.com"
                        End With
                        .Item("ManHoursConsumed") = "0.25"
                    End With
                End With
            End With
        End With
        SendSmartMessage JB.JSON
    End Sub
    The issue is to do with the array formation I think.

    Thanks Simon

  6. #126
    Frenzied Member
    Join Date
    Sep 2012
    Posts
    2,041

    Re: VB6 - JsonBag, Another JSON Parser/Generator

    Hi dilettante, I'd like to know if your JsonBag can read JavaScript objects, for example:

    Code:
    {
        start: 0,
        end: 15,
        source: "AAA",
        type: "BBB"
    }
    IMO, the main difference between JavaScript objects and JSON strings is that Key names have no double quotes.

  7. #127

  8. #128
    Frenzied Member
    Join Date
    Sep 2012
    Posts
    2,041

    Re: VB6 - JsonBag, Another JSON Parser/Generator

    Quote Originally Posted by wqweto View Post
    The format is called JSON5 - JSON for humans.

    cheers,
    </wqw>
    Oh, great. I like JavaScript. Thank you very much, wqweto.

  9. #129
    New Member
    Join Date
    May 2020
    Posts
    4

    Re: VB6 - JsonBag, Another JSON Parser/Generator

    hi I can get the json report of the products between the date I want on my opencart site but how to write this incoming data in a text file with 6.0 etc. thanks


    sample:

    [{"UrunKodu":"7209","UrunAdi":"Apple phone 7 Plus Dolu Kasa Jet Black","Ucret":"35.0000"}]


    write txt sample data

    UrunKodu=7209,UrunAdi=Apple phone 7 Plus Dolu Kasa Jet Black,Ucret=35.0000


    orjinal file:


    [{"UrunKodu":"7209","UrunAdi":"Apple \u0130phone 7 Plus Dolu Kasa- Jet Black","Ucret":"35.0000","StokMiktari":"7"},{"UrunKodu":"7206","UrunAdi":"Apple \u0130phone 6S Plus Dolu Kasa- Gold","Ucret":"40.5000","StokMiktari":"7"},{"UrunKodu":"11821","UrunAdi":"Huawei GR5 \u015earj Ve Mikrofon Bordu","Ucret":"8.0000","StokMiktari":"2"},{"UrunKodu":"11765","UrunAdi":"Apple Iphone 8 \u00d6n Kamera+Sens\u00f6r Filmi","Ucret":"15.0000","StokMiktari":"8"},{"UrunKodu":"7230","UrunAdi":"Samsung Galaxy J2 Pro (J250) Kasa+ Kapak- Silver","Ucret":"10.0000","StokMiktari":"12"},{"UrunKodu":"7204","UrunAdi":"Apple \u0130phone 6S Plus Dolu Kasa- Beyaz","Ucret":"30.0000","StokMiktari":"7"},................]

  10. #130
    Hyperactive Member
    Join Date
    Jan 2020
    Posts
    418

    Re: VB6 - JsonBag, Another JSON Parser/Generator

    i test json2.js is the best(used time :16 ms,JsonBag,38ms)
    ---------------------------
    In the case of large files, I eventually lost to the JS object
    After all, that is native JS, VB still has to parse

    50K JSON string to object, object to character
    Json1, time: 18.162882
    Json2, time: 16.407462
    Json3, time: 41.214192
    vbjson, time: 125.604048
    JsonConverter, time: 40.81495
    cDataJSON, time: 48.869498
    JsonBag, time: 38.097204
    ---------------------------

    50K large file, Json object to string
    Json1, time: 28.468988
    Json2, time: 17.008122
    Json3, time: 38.91001
    vbjson, time: 83.524864
    JsonConverter, time: 18.332476
    cDataJSON, time: 7.14318
    JsonBag, time: 21.876478

  11. #131
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,906

    Re: VB6 - JsonBag, Another JSON Parser/Generator

    Quote Originally Posted by xiaoyao View Post
    i test json2.js is the best(used time :16 ms,JsonBag,38ms)
    ---------------------------
    In the case of large files, I eventually lost to the JS object...
    Your results are not really meaningfull, unless you include:
    - the data you did use
    - and your test-code

    Here is an example, which shows, where the (JSON-)data came from (a Download-URL),
    and it includes the complete test-code as well (based on the RC5-JSON-functions).

    Code:
    Option Explicit
    
    Private sJSONinp As String
    
    Private Sub Form_Load()
      Dim D As cDownloads
      Set D = New_c.Downloads 'download a larger JSON-file into an inp-string first
      With D.Download("https://www.sba.gov/sites/default/files/data.json")
        If .WaitForCompletion(15) Then sJSONinp = New_c.Crypt.UTF8ToVBString(.GetContentData)
      End With
    End Sub
    
    Private Sub Form_Click()
      New_c.Timing True
        Dim oJSON As cCollection
        Set oJSON = New_c.JSONDecodeToCollection(sJSONinp)  'decode the JSON-string to Object
      Debug.Print "JSON-decoding of " & Len(sJSONinp) & " Chars took:" & New_c.Timing
      
      New_c.Timing True
        Dim sJSONout As String
            sJSONout = oJSON.SerializeToJSONString 'serialize the Object back into a JSON-string
      Debug.Print "JSON-encoding to " & Len(sJSONout) & " Chars took:" & New_c.Timing
    End Sub
    Here the results on the quite large (1.3MB, not 50kB) test-input:
    Code:
    JSON-decoding of 1342902 Chars took: 43.84msec
    JSON-encoding to 1321953 Chars took: 26.87msec
    Olaf

  12. #132
    Hyperactive Member
    Join Date
    Jan 2020
    Posts
    418

    Re: VB6 - JsonBag, Another JSON Parser/Generator

    cConstructor ,RC5-JSON(cConstructor vbRichClient5.DLL)
    This method runs the fastest, can you share the source code?
    thank you.
    Code:
    Json1Code = "var JSON=function(){var m={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','""':'\\""','\\':'\\\\'},s={'boolean':function(x){return String(x)},number:function(x){return isFinite(x)?String(x):'null'},string:function(x){if(/[""\\\x00-\x1f]/.test(x)){x=x.replace(/([\x00-\x1f\\""])/g,function(a,b){var c=m[b];if(c){return c}c=b.charCodeAt();return'\\u00'+Math.floor(c/16).toString(16)+(c%16).toString(16)})}return'""'+x+'""'},object:function(x){if(x){var a=[],b,f,i,l,v;if(x instanceof Array){a[0]='[';l=x.length;for(i=0;i<l;i+=1){v=x[i];f=s[typeof v];if(f){v=f(v);if(typeof v=='string'){if(b){a[a.length]=','}a[a.length]=v;b=true}}}a[a.length]=']'}else if(x instanceof Object){a[0]='{';for(i in x){v=x[i];f=s[typeof v];if(f){v=f(v);if(typeof v=='string'){if(b){a[a.length]=','}a.push(s.string(i),':',v);b=true}}}a[a.length]='}'}else{return}return a.join('')}return'null'}};return{"
    Json1Code = Json1Code & "copyright: '(c)2005 JSON.org',license:'http://www.crockford.com/JSON/license.html',stringify:function(v){var f=s[typeof v];if(f){v=f(v);if(typeof v=='string'){return v}}return null},parse:function(text){try{return!(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(text.replace(/""(\\.|[^""\\])*""/g,'')))&&eval('('+text+')')}catch(e){return false}}}}();"
    
    Htm = "{""a"":""3333"",""b"":""abc"",""arr1"":[{""c"":""aa"",""d"":""bb""},{""e"":""dd""}]}"
    
    Dim Js As ScriptControl, JsonStr As String
    Set Js = New ScriptControl
    Js.Language = "Javascript"
    Js.AddCode "var JsonObj=" & Htm 
    
    Js.AddCode Json1Code
    JsonStr = Js.Eval("JSON.stringify(JsonObj)")  
    
    MsgBox "JsonStr=" & JsonStr
    Jsontxt from:"https://www.sba.gov/sites/default/files/data.json" (1.3MB SIZE)
    ----------------
    StrToJsonObject+ObjectToSTR:

    cConstructor ,Time(ms):74.62878
    Json1 ,Time(ms):193.73442
    Json2 ,Time(ms):173.22444
    Json3 ,Time(ms):1166.90108
    vbjson ,Time(ms):7827.51336
    JsonConverter,Time(ms):6587.33684
    cDataJSON ,Time(ms):1351.50216
    JsonBag ,Time(ms):2364.81656
    ----------------
    JsonObjectToStr:

    cConstructor ,Time(ms):32.69154
    Json1 ,Time(ms):172.668
    Json2 ,Time(ms):155.47996
    Json3 ,Time(ms):1149.53676
    vbjson ,Time(ms):7333.60354
    JsonConverter,Time(ms):6136.69794
    cDataJSON ,Time(ms):558.91872
    JsonBag ,Time(ms):1812.21622
    Last edited by xiaoyao; May 12th, 2020 at 03:42 AM.

Page 4 of 4 FirstFirst 1234

Tags for this Thread

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