jsonData is
{
"S_Client.packet": [
{
"DESC": "2",
"NO": 2,
"SEND": [
{
"PARAM": "1",
"TYPE": null,
"VALUE": "11"
}
],
"RECEIVE": []
}
]
}
I want get data set using method( JsonConvert.DeserializeObject(jsonData) ) but "RECEIVE":[] < last character run Exception..
different types was well done..
and not first data(DataTable in DataSet and blank array) was also well done..
I think that was bug to report
Related
so I want to be able to extract and ID based on whether that object has a particular property. I NEED this to be done via Regex. Here is an example of the JSON I am working with:
{
"workspaceid": ws01,
"data": {
"workspacetitle": "My Workspace"
},
"collections": {
"projects": [{
"id": 01,
"data": {
"title": "My Project 01",
"enddateperiod": "2020-02-20T23:59:59",
"profilecomplete": true,
"synced": false
},
"lists": {
"projectcode": [{
"id": pcodered,
"data": {
"code": "myproject123",
"name": "OffshoreProject"
}
}]
}
}, {
"id": 02,
"data": {
"title": "My Project 02",
"enddateperiod": "2020-02-20T23:59:59",
"profilecomplete": false,
"synced": false
},
"lists": {
"projectcode": [{
"id": pcodered,
"data": {
"code": "myproject123",
"name": "OffshoreProject"
}
}]
}
}]
}}
So what I want to extract is the ID of the project whose profile is not complete ("profilecomplete":false). So in this case, I want to select Project 2's id (which is 02).
How can I do this via Regex? I've managed to remove all of the whitespace and new lines as well so the JSON is essentially all one long line. Would it be easier to extract the Regex like this? Either way, I could use some help on how to get this ID.
NOTE: The format of the JSON cannot change.
This one works
/"id": ([^,]*?)(?=,[^{]*{[^}]*"profilecomplete": false)/
Explanations :
Read all these chars first "id":[space]
Then read in a group chars that aren't ","
And then a lookahead : you expect "," then chars that aren't "{", then "{"; and finally, before matching the closing "}", you want to read "profilecomplete": false
But I agree that a JSON parser would have been my preferred option!
The JSON string will be like below
{"data": [{
"id": "BankDetails.FirstName",
"value": "abcd",
"type": "Text"
},
{
"id": "BankDetails.AccountNumber",
"value": "12345678",
"type": "Text"
},
{
"id": "BankDetails.SortCode",
"value": "123",
"type": "Text"
}]
}
The "value": "12345678" under the "id": "BankDetails.AccountNumber" should be replaced as "value": "********". How can we write a Regex Pattern for this?
So the exact output will be
{"data": [{
"id": "BankDetails.FirstName",
"value": "abcd",
"type": "Text"
},
{
"id": "BankDetails.AccountNumber",
"value": "********",
"type": "Text"
},
{
"id": "BankDetails.SortCode",
"value": "123",
"type": "Text"
}]
}
Note: BankDetails.AccountNumber will not always be the third object.
You can use variable width positive look behind (supported in C#) to target each digit and replace it with * using this regex,
(?<="id": "BankDetails.AccountNumber",\s*"value": "\d*)\d
Regex Demo
Have tried several methods described but not winning. Here is the value ofthe var valuesEntity (this is from Luis integration into bot framework).
I have not found a way to interrogate this var so that I get a variable with the value of Venue - in this case Bakery.
{{
"$instance": {
"Venue": [
{
"startIndex": 13,
"endIndex": 19,
"text": "bakery",
"type": "Venue"
}
]
},
"Venue": [
[
"BAKERY"
]
]
}}
"Venue" is an string[][], Venue[0][0], should return "BAKERY".
This would be a valid json:
{
"$instance": {
"Venue": [{
"startIndex": 13,
"endIndex": 19,
"text": "bakery",
"type": "Venue"
}]
},
"Venue": [
[
"BAKERY"
]
]
}
You can check for valid json on https://jsonlint.com/
The key was to deserialize the Jason object to a Jason string.
I am building a BOT using Microsoft Bot framework in C# and LUIS.
Using the prebuilt entity datetime.V2, I am able to capture terms like "last week", "next month" etc. properly.
However I am struck when it comes to:
"Get me all products which has expiry life greater than 2 years",
"greater than today",
"> today" etc.,
Do I use LUIS composite entities? If so, would "Greater than" and "today" become the child for a composite entity named say, "DateComparer"?
Is there any github sample that I can refer to to understand how composite entites would be parsed?
Thanks for your help and time in advance.
I created a ComparerList taking Miskov's suggestion.
"composites": [
{
"name": "DateComparer",
"children": [
"ComparerList",
"datetimeV2"
]
}
],
"closedLists": [
{
"name": "ComparerList",
"subLists": [
{
"canonicalForm": "gt",
"list": [
"greater than",
"larger than",
"more than",
"over",
"exceeding",
"higher than",
">"
]
},
{
"canonicalForm": "lt",
"list": [
"<",
"less than"
]
},
{
"canonicalForm": "eq",
"list": [
"=",
"equal to"
]
},
{
"canonicalForm": "le",
"list": [
"<=",
"less than or equal to"
]
},
{
"canonicalForm": "ge",
"list": [
">=",
"greater than or equal to"
]
}
]
}
],
"bing_entities": [
"datetimeV2"
],
I am able to train Luis to return the following json based on
utterances like "Give me all items with expiry greater than yesterday".
And I get the following json back when testing.
"entities": [
{
"entity": "greater than",
"type": "ComparerList",
"startIndex": 33,
"endIndex": 44,
"resolution": {
"values": [
"gt"
]
}
},
{
"entity": "greater than yesterday",
"type": "DateComparer",
"startIndex": 33,
"endIndex": 54,
"score": 0.6950233
},
{
"entity": "yesterday",
"type": "builtin.datetimeV2.date",
"startIndex": 46,
"endIndex": 54,
"resolution": {
"values": [
{
"timex": "2017-09-14",
"type": "date",
"value": "2017-09-14"
}
]
}
}
From this, I retrieve the "gt" resolution and use it in my code.
This question already has answers here:
Order of serialized fields using JSON.NET
(15 answers)
JSON order mixed up
(17 answers)
Closed 6 years ago.
I tryed to read a json file, edit it and then save it again, everything works fine except the order of the values in the new json file is wrong.
Here a part of the Original Json file:
"files": [
{
"name": "Game.cfg",
"sections": [
{
"name": "Chat",
"settings": [
{
"name": "ChatX",
"value": "44"
},
{
"name": "ChatY",
"value": "74"
},
{
"name": "Transparency",
"value": "0.0000"
}
]
},
and here the the same part in the new json file i create:
"files": [
{
"sections": [
{
"settings": [
{
"name": "ChatX",
"value": "44"
},
{
"name": "ChatY",
"value": "74"
},
{
"name": "Transparency",
"value": "0.0000"
}
],
"name": "Chat"
},
and here the code if needed:
string filename = filesource;
var res = JsonConvert.DeserializeObject<PersistentSettings>(File.ReadAllText(filename));
List<PersistentSettings> pers = new List<PersistentSettings>();
pers.Add(res);
string json = JsonConvert.SerializeObject(pers, Formatting.Indented);
//write string to file
File.WriteAllText("test.json", json);
like i said it works just not as it should, anyone got an idea why?