Guidelines on how to dissect a JavaScript code or array using C#

Upon receiving a web request for a JavaScript file, a JavaScript Snippet was retrieved as the response that needs to be parsed in C#.

The snippet contains data like:

sDt[1647110]=['SVK U19 A','D43A71','Jupie Podlavice Badin(U19)','TJ Straza(U19)','','',' / '
,'','',114745,114746,1,'',0,0,0,1012,1,'','',''];sDt[1647108]=['SVK U19 A','D43A71','Kysucke Nove Mesto(U19)',
'MFK Lokomotiva Zvolen(U19)','','',' / ','','',114741,114742,1,'',0,0,0,1012,1,'','',''];
sDt[1647109]=['SVK U19 A', /* Many more similar entries followed by */ ;WLID[1623901]=1;
WLID[1623902]=1;WLID[1623903]=1;WLID[1637686]=1;
WLID[1637692]=1;WLID[1637687]=1;WLID[1637688]=1;WLID[1637685]= /* ending with */ 
var ORD = [1647110,1647108,1647109,1647133,1645669,1647122,1626152,1647251,1646643,
1647130,1646685,1 ... ];

This doesn't conform to a standard JSON array format. The challenge is to parse this efficiently. Initially, an attempt was made using String.Split, which proved to be slow and unstable.

The goal is to extract the array behind each sDt[Identifier] along with its corresponding Identifier using Json.Net, while disregarding other elements like WLID or var ORD.

If you have any suggestions on how to tackle this problem efficiently, please share. Your help is much appreciated!

Answer №1

To properly dissect the request, one must meticulously analyze each token without any other aids or shortcuts. It's imperative to follow this process thoroughly. Have you considered simply sending the JSON instead? When parsing, here's a suggested method: Carefully examine the entire request. If you encounter an opening square bracket '[', ensure that you are not inside a string at that moment. You can achieve this by setting a flag when encountering a '"', and unsetting it after another '"'. When not within a string, subsequent tokens will either be identifiers or content, which can be easily determined. For numbers, the identifier extends until reaching ']'. For non-numeric values, treat them as content to be parsed with Json.Net. Note the positions of '[' and ']' to extract the necessary substring for Json.Net. Should you encounter a ';', make sure to skip over the sections labeled WLID and ORD if not inside a string. Overall, this process has a time complexity of O(n * m) where n represents the number of tokens and m is the length of the longest content string. By handling the content parsing manually (rather than relying on Json.Net), the time complexity could potentially be reduced to O(n).

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Retrieving the status of a checkbox using jQuery to obtain a value of 1 or

Incorporating jQuery, I am able to retrieve the values of all input fields using the provided code snippet. However, an issue arises when dealing with checkboxes as they return "on" if checked. How can I modify this to receive a value of 1 when a checkbox ...

Troubleshooting a problem with data retrieval in Hygraph and Next JS

I'm currently facing an issue while attempting to fetch data from Hygraph in a fresh Next JS application. The error message I'm encountering is: Error: Cannot read properties of undefined (reading 'map'). As a beginner in both technolo ...

Unknown and void

undefined === null => false undefined == null => true I pondered the logic behind undefined == null and realized only one scenario: if(document.getElementById() == null) .... Are there any other reasons why (undefined === null) ...

Exploring the Factory Design Pattern Together with Dependency Injection in Angular

I'm currently implementing the factory design pattern in Angular, but I feel like I might be missing something or perhaps there's a more efficient approach. My current setup involves a factory that returns a specific car class based on user input ...

Trouble with shadow rendering in imported obj through Three.js

After importing an object from blender and setting every mesh to cast and receive shadows, I noticed that the rendered shadows are incorrect. Even after merging the meshes thinking it would solve the issue, the problem persisted. It seems like using side: ...

Creating an interactive table populated with data from a JSON file using JavaScript

Using this JSON data as the basis for developing a table, I am facing challenges in adding rows based on columns. [ { "authType": "BasicAuth", "phases": [ { "type": "Development", "keys":[{ "username": "developer" },{ "password": ...

Get a PDF file from MongoDB via jade Template Engine

Currently, I am utilizing Node, along with express, Jade, and a MongoDB to query the database and showcase the data on a webpage. Within the database, PDFs are stored and my goal is to enable users to download these files directly from the webpage. While ...

Deriving a subject line by combining two values from two different inputs

There is a form that I am submitting which includes a hidden field for the subject line with a value of 'Faulty Item'. https://jsfiddle.net/k8tnns73/ $(document).ready (function(){ $('#zendesk_field_zen_subject input').val(' ...

I'm struggling to remove a record from the grid view without any success

I'm having trouble removing a record from the grid view. Whenever I try to delete a record using a link button in a template field, I encounter this error: var id = GvTestimony.DataKeys[gvRow.RowIndex].Value.ToString(); The error message reads a ...

Having issues converting a dictionary into JSON using TouchJson

I'm currently working on a project for the iPad where I am attempting to convert a dictionary into NSData in order to save it to the disk. I am utilizing the TouchJson framework. Here is an example of the structure I am working with: { line = { ...

Saving complex array objects to a device using NSKeyedArchiver in Swift: A comprehensive guide

How can I save an array of a class (for example, let's say SymptomsModel) type into a device using NSKeyedArchiver in Swift? I have figured out how to save an array if the SymptomsModel class contains variables with primitive data types, but I'm ...

What is the best way to tailor specific text in d3.js?

I need assistance with customizing the appearance of an asterisk added to the end of a template literal in d3js. I want to be able to independently adjust the size and color of the asterisk regardless of the variable it's attached to. Below is the cod ...

Verify the presence of blank space with javaScript

I currently have a text box on my website. <input type="text" name="FirstName" value="Mickey"> My goal is to prevent the user from entering empty spaces, tabs, or new lines in the text box. However, I want to allow spaces between characters. Does a ...

Adjust the size of an IFRAME to eliminate scrollbars from appearing

My webpage features an iframe that needs to be resized dynamically each time its contents change in order to eliminate scrollbars. The content inside the iframe frequently changes without altering the URL. I desire for all the content within the frame to b ...

How can I prevent media controls from appearing in fullscreen mode on Microsoft Edge using CSS?

My video code allows for switching the video into fullscreen mode using custom controls. Here's how it looks: fullScreenButton.addEventListener("click", function() { if (video.requestFullscreen) { video.videoContainer.r ...

Exploring the depths of nested object arrays

I'm really struggling to complete a FullStackOpen exercise that requires rendering data to the page. With the following code, I need to display the number of Parts each Course has and also reduce the number of Exercises/Parts to show the total exercis ...

Select Additional Component in Empty Area (Using Angular.js with HTML, JS, CSS)

In my ng-repeat, elements are highlighted on hover of the main div and a lightbox appears upon clicking an element. However, there is empty space below each element where cursor changes to pointer and lightbox opens. This phantom area is causing a false sc ...

Having trouble displaying a popup dialog box in ASP.NET using JavaScript

I am trying to implement a popup dialog box in ASP.NET using JavaScript, but it's not working as expected! Below is the code I am using: <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal< ...

Not getting expected response from Angular 5 HTTP request

My HTTP calls are not firing as expected. I have set up the call in the subscribe method of route params. Strangely, the call only triggers on full page reload or when I first click a button to change the route. After that initial trigger, the call doesn&a ...

Tips on enabling or disabling an ASP button based on the selected value in a dropdown using a JavaScript function

I have an ASP dropdown and a button. I need the button to be disabled when the dropdown's selected value is the first index, and enabled when any other value is selected. Here is my code, however, it is not functioning as expected: function checkSele ...