Click here to Skip to main content
15,943,477 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
ian try serialez json object to get this resulte :


What I have tried:

If jObj.Type = JTokenType.String Then
            Return "" & jObj.Value(Of String)() & ""
        End If

        Dim serializedString As StringBuilder = New StringBuilder()

        For Each item In jObj.Children().ToList
            If item.Type <> JTokenType.Array Then
                Dim jObjItem = item.ToObject(Of JObject)()
                For Each itemKeyPair In jObjItem
                    serializedString.Append(Chr(34) & itemKeyPair.Key.ToUpper() & Chr(34))
                    ' serializedString.Append(Chr(34) & itemKeyPair.Value.ToString & Chr(34))

            End If

            '            JsonObject2 := JSONObject.SelectToken('item.CityAliases');

            'FOREACH Element IN JSONObject2 DO
            '  BEGIN
            '            Value := JSONObject2.SelectToken('Item.CityAliasName');
            '    If CONFIRM('AliasName = ' + FORMAT(Value)) THEN;  <<--Returns NULL
            '  END;

            If item.Type = JTokenType.Array Then
                Dim jArrItem = item.ToObject(Of JArray)()
                serializedString.Append("" & jArrItem.ToString & "")

                For Each jobjsItems In jArrItem.Children()
                    Dim jObjItem = jobjsItems.ToObject(Of JObject)()

                    For Each itemKeyPair In jObjItem
                        serializedString.Append("" & itemKeyPair.Key.ToUpper() & "")
            End If

        Return serializedString.ToString()
Updated 27-Dec-22 11:29am

That isn't JSON: It's just a bunch of strings delimited by double quote pairs concatenated together.
JSON data is hierarchical, and looks like this sample array:
		color: "red",
		value: "#f00"
		color: "green",
		value: "#0f0"
		color: "blue",
		value: "#00f"
		color: "cyan",
		value: "#0ff"
		color: "magenta",
		value: "#f0f"
		color: "yellow",
		value: "#ff0"
		color: "black",
		value: "#000"
I'd start by checking exactly what you are expected to produce, and if it is JSON then use something like Newtonsoft.Json to generate it.
Share this answer
Member 13788770 27-Dec-22 15:49pm    
Algorithm Overview
The algorithm to implement when serializing data to get hash code to sign is:

Documents processed recursively, starting from the root element of the document. See the note below!
All property names are converted to culture invariant uppercase.
All property values are taken without any processing, just like those are in the input document. E.g., if original document has value 0.0, it should be moved to serialized string as 0.0 and cannot be moved as 0 or 0.00.
All property names and simple type values (those, which are not objects) are enclosed into double quotes symbol ".
In JSON – entire array serialization result is prefixed with the array property name and every array element is preceded with the array property name. This is one place, where difference with XML exists, as in XML there would be one prefix for the entire array serialization output and other names for individual elements. E.g.:
In JSON we would receive something like “TAXABLEITEMS”“TAXABLEITEMS”<taxable item="" #1="" serialization="" output="">“TAXABLEITEMS”<taxable item="" #2="" serialization="" output=""> …
While in XML: “TAXABLEITEMS”“TAXABLEITEM”<taxable item="" #1="" serialization="" output="">“TAXABLEITEM”<taxable item="" #2="" serialization="" output=""> …
OriginalGriff 27-Dec-22 16:04pm    
Have you noticed that the purported JSON and XML in that description are both identical, and that neither of them are JSON or XML data?

I'd go back where you found that assignment, and ask for clarification...
As OriginalGriff points out, that is not JSON data. You can check if you have valid JSON data here: JSON Online Validator and Formatter - JSON Lint[^]

I have also written comprehensive article series on this subject, first of which is here: Working with Newtonsoft.Json in C# & VB[^]. They should answer all of your questions.
Share this answer
Pseudo Code Implementation
Implementation for JSON:

function string Serialize(documentStructure)
    if documentStructure is simple value type
        return """ + documentStructure.value + """
    end if

    var serializedString = ""
    foreach element in the structure:
        if element is not array type
            serializeString.Append (""" + + """)
            serializeString.Append ( Serialize(element.value) )
        end if

        if element is of array type
            serializeString.Append (""" + + """)
            foreach array element in element: 
                // use below line for JSON because subelements of array in JSON do not have own names
                serializeString.Append (""" + + """)         
                serializeString.Append ( Serialize(arrayelement.value) )              
            end foreach
        end if

    end foreach

    return serializedString
end function
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900