Categories: c#, json

Extract attribute Value from JSON String using c#

1 answer

enter image description hereI'm looking for a best possible way to extract the JSON attribute - RatingData using c#. See the JSON string below.

Please note that the JSON attribute "RatingData" is digitally signed using a private key and I'm trying to verify the digital signature using public key and signature. I need to extract RatingData as it was sent in the JSON to make sure digital signature verification passes. I tried JObject parsing but this technique seems to return spaces and doesn't work well.

Any other technique to retrieve the JSON Attribute information as it is being sent?

{   "DigitalSignature": "MEYCIQDC0RutOfYEIR/3zkUlcIxxxxxx98Ayqq8AIhAP30+Bk8ueY1ABVYJlAQGlhAcWlAMHo3YAqhHIrUykUj",   "ReceiptPublicKey": "RxxxxxIN7I3IhLjAqrUrx5vZofHYm4DF5srHB0Hzyuf25eW5UVCPOvbr8GvrzqZbq2ZdcQmAaoiyhaBcOdAsjcHYBcfV/tR5uHQRDLWIpNUTawcxB6tX6XGXvd0baPav4LfL2pfqegpx5BhfWdRGmvL6/Yc5bw29IWag/SmabTEZE/C4=",   "RatingData": {     "RatingValue": 3,     "ItemID": "15cc6a0b-9673-4537-b5cc-b205249f44e4",     "RatingDateTime": "2020-03-21 00:36:49.025",     "Rating": [       3,       3,       5     ]   },   "RetailersReceiptData": {     "ConsumerID": "d9e1c467-91c6-4afe-ae7c-86b0a0d0bfb3",     "RetailerID": "6da5da9f-b42d-4918-ad43-53b2203df54e",     "RetailerRulePoints":      {       "Enablexxx": 1,       "Enableyyy": 1,       "Enablezzz": 1     }   } } 

All answers to this question, which has the identifier 60793237

The best answer:

Check this Net fiddle. I'm using the Newtonsoft Json library to do the converion

using System; using Newtonsoft.Json;  public class Program {     static string json = "{ \"DigitalSignature\": \"MEYCIQDC0RutOfYEIR/3zkUlcIxxxxxx98Ayqq8AIhAP30+Bk8ueY1ABVYJlAQGlhAcWlAMHo3YAqhHIrUykUj\",  \"ReceiptPublicKey\": \"RxxxxxIN7I3IhLjAqrUrx5vZofHYm4DF5srHB0Hzyuf25eW5UVCPOvbr8GvrzqZbq2ZdcQmAaoiyhaBcOdAsjcHYBcfV/tR5uHQRDLWIpNUTawcxB6tX6XGXvd0baPav4LfL2pfqegpx5BhfWdRGmvL6/Yc5bw29IWag/SmabTEZE/C4=\",  \"RatingData\": {    \"RatingValue\": 3,    \"ItemID\": \"15cc6a0b-9673-4537-b5cc-b205249f44e4\",    \"RatingDateTime\": \"2020-03-21 00:36:49.025\",    \"Rating\": [      3,      3,      5    ]  },  \"RetailersReceiptData\": {    \"ConsumerID\": \"d9e1c467-91c6-4afe-ae7c-86b0a0d0bfb3\",    \"RetailerID\": \"6da5da9f-b42d-4918-ad43-53b2203df54e\",    \"RetailerRulePoints\":     {      \"Enablexxx\": 1,      \"Enableyyy\": 1,      \"Enablezzz\": 1    }  }}";     public static void Main()     {         dynamic obj  = JsonConvert.DeserializeObject<dynamic>(json);          Console.WriteLine(obj.DigitalSignature);         Console.WriteLine(obj.ReceiptPublicKey);     } } 

MEYCIQDC0RutOfYEIR/3zkUlcIxxxxxx98Ayqq8AIhAP30+Bk8ueY1ABVYJlAQGlhAcWlAMHo3YAqhHIrUykUj

RxxxxxIN7I3IhLjAqrUrx5vZofHYm4DF5srHB0Hzyuf25eW5UVCPOvbr8GvrzqZbq2ZdcQmAaoiyhaBcOdAsjcHYBcfV/tR5uHQRDLWIpNUTawcxB6tX6XGXvd0baPav4LfL2pfqegpx5BhfWdRGmvL6/Yc5bw29IWag/SmabTEZE/C4=

Last questions

how do i remove the switch on my home screen?
how to edit the JS date and time to update atuomatically?
How to utilize data stored in a multidimensional array
Powermockito not mocking URL constructor in URI.toURL() method
Android Bluetooth LE Scanner only scans when phone's Location is turned on in some devices
docker wordpress container can't connect to mysql container
How can I declare a number in java that is more than 64-bits? [duplicate]
Optaplanner solutionClass entityCollectionProperty should never return null error when simple JSON object passed to controller
Anylogic, get the time a pedestrain is in a queue
How do I fix this syntax issue with my .flex file?
Optimizing query in PHP
How to find the highest number of a column and print two columns of that row in R?
Ideas on “Error: Type com.google.firebase.iid.zzav is referenced as an interface from com.google.firebase.messaging.zzd”?
JCIFS SmbFile.exists() and SmbFile.isDirectory() return false when it exists and I can listFiles()
PHP total order
Laravel booking system design
neural net - undefined column selected
How to indicate y axis does not start from 0 in ggplot?
Fragments in backStack
Spinner how to change the data