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 :

"HEADER""DATETIMEISSUED""2022-12-25T00:34:00Z""RECEIPTNUMBER""INV-2012""UUID""""PREVIOUSUUID""""REFERENCEOLDUUID""""CURRENCY""EGP""EXCHANGERATE""0""SORDERNAMECODE""SORDERNAMECODE""ORDERDELIVERYMODE""FC""DOCUMENTTYPE""RECEIPTTYPE""SC""TYPEVERSION""1.2""SELLER""RIN""619013583""COMPANYTRADENAME""شركة الصوفى""BRANCHCODE""0""BRANCHADDRESS""COUNTRY""EG""GOVERNATE""CAIRO""REGIONCITY""CITY CENTER""STREET""16 STREET""BUILDINGNUMBER""14BN""POSTALCODE""74235""FLOOR""1F""ROOM""3R""LANDMARK""TAHRIR SQUARE""ADDITIONALINFORMATION""TALAAT HARB STREET""DEVICESERIALNUMBER""SOFT2010""ACTIVITYCODE""5610""BUYER""TYPE""F""ID""313717919""NAME""TAXPAYER 1""MOBILENUMBER""+201020567462""PAYMENTNUMBER""987654""ITEMDATA""ITEMDATA""INTERNALCODE""880609""DESCRIPTION""SAMSUNG A02 32GB_LTE_BLACK_DS_SM-A022FZKDMEB_A022 _ A022_SM-A022FZKDMEB""ITEMTYPE""GS1""ITEMCODE""EG-619013583-102""UNITTYPE""EA""QUANTITY""35""UNITPRICE""247.96000""NETSALE""7810.74000""TOTALSALE""8678.60000""TOTAL""8887.04360""COMMERCIALDISCOUNTDATA""COMMERCIALDISCOUNTDATA""AMOUNT""867.86000""DESCRIPTION""XYZ""ITEMDISCOUNTDATA""ITEMDISCOUNTDATA""AMOUNT""10""DESCRIPTION""ABC""ITEMDISCOUNTDATA""AMOUNT""10""DESCRIPTION""XYZ""VALUEDIFFERENCE""20""TAXABLEITEMS""TAXABLEITEMS""TAXTYPE""T1""AMOUNT""1096.30360""SUBTYPE""V009""RATE""14""TOTALSALES""8678.60000""TOTALCOMMERCIALDISCOUNT""867.86000""TOTALITEMSDISCOUNT""20""EXTRARECEIPTDISCOUNTDATA""EXTRARECEIPTDISCOUNTDATA""AMOUNT""0""DESCRIPTION""ABC""NETAMOUNT""7810.74000""FEESAMOUNT""0""TOTALAMOUNT""8887.04360""TAXTOTALS""TAXTOTALS""TAXTYPE""T1""AMOUNT""1096.30360""PAYMENTMETHOD""C""ADJUSTMENT""0" 


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(itemKeyPair.Value.ToString)
                    serializedString.Append(Serialize(item))
                    ' serializedString.Append(Chr(34) & itemKeyPair.Value.ToString & Chr(34))

                Next
            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() & "")
                        serializedString.Append(Serialize(item))
                    Next
                Next
            End If
        Next

        Return serializedString.ToString()
Posted
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:
JSON
[
	{
		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
 
Comments
Member 13788770 27-Dec-22 15:49pm    
its
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 (""" + element.name.uppercase + """)
            serializeString.Append ( Serialize(element.value) )
        end if

        if element is of array type
            serializeString.Append (""" + element.name.uppercase + """)
            foreach array element in element: 
                // use below line for JSON because subelements of array in JSON do not have own names
                serializeString.Append (""" + element.name.uppercase + """)         
                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