csv zuwa json online

Yadda ake canza CSV zuwa JSON tare da NET Cloud SDK.

A cikin yanayi mai ƙarfi na sarrafa bayanai, ikon canza [CSV] (https://docs.fileformat.com/spreadsheet/csv/) zuwa [JSON] (https://docs.fileformat.com/web/json) /) ginshiƙi ne don ingantaccen sarrafa bayanai. Labarin mu na baya-bayan nan ya nutse cikin mahimman buƙatun wannan juzu’i, yana magance ƙalubale da damar da yake buɗewa. Ko da yake ana amfani da fayilolin CSV (Dabi’u-Wakafi-Wakafi) ko’ina, amma za su iya yin kasala idan aka zo ga tsarin tsarin bayanai da tsarin gida. Saboda haka, JSON (JavaScript Bayanin Bayani), tare da sassaucin ra’ayi na asali, yana ba da ingantaccen bayani don wakiltar hadaddun alaƙar bayanai. Don haka, bari mu fara tafiya don ƙarfafa bayananku tare da ingantaccen sassauci da tsari ta amfani da NET Cloud SDK.

API ɗin NET REST don CSV zuwa Juyawa JSON

Shiga cikin tafiyar juyar da CSV zuwa JSON yana da ƙarfi da ƙarfi tare da Aspose.Cells Cloud SDK don NET. Wannan ƙwaƙƙwaran SDK yana ba da cikakkun kayan aikin don canza fayilolin CSV ɗinku cikin tsari na JSON mai yawa. Daga sarrafa hadadden tsarin bayanai zuwa kiyaye amincin bayanai, SDK yana yin jujjuya bayanai cikin sauƙi, yana tabbatar da daidaito da sassauci.

Mataki na farko a wannan hanyar shine bincika ‘Aspose.Cells-Cloud’ a cikin manajan fakitin NuGet kuma danna maɓallin ‘Ƙara Kunshin’. Na biyu, sami takaddun shaidar abokin ciniki daga dashboard ɗin girgije. Idan ba ku da asusun da ke akwai, kawai ƙirƙirar asusun kyauta ta bin umarnin da aka kayyade a cikin labarin saurin farawa.

Maida CSV zuwa JSON a cikin C# .NET

Bari mu bincika cikakkun bayanai kan yadda za mu iya canza tsarin CSV zuwa tsarin JSON a cikin C# .NET.

CellsApi cellsInstance = new CellsApi(clientID, clientSecret);

Da farko, ƙirƙiri wani abu na ajin CellsApi inda muke ƙaddamar da shaidar abokin ciniki azaman muhawara.

SaveOptions saveOptions = new SaveOptions()

Na biyu, ƙirƙirar misali na SaveOptions inda muke ayyana tsarin fitarwa azaman JSON.

PostWorkbookSaveAsRequest postworkbookSaveAsRequest = new PostWorkbookSaveAsRequest()

Na uku, ƙirƙiri misali na ‘PostWorkbookSaveAsRequest’ inda muka ƙididdige sunan shigar da fayil ɗin CSV, sunan sakamako JSON da sauran sigogi zuwa ginshiƙan AutoFit da layuka.

cellsInstance.PostWorkbookSaveAs(postworkbookSaveAsRequest);

Kira API don canza CSV zuwa tsarin JSON akan layi. Da zarar an yi nasarar aiwatar da lambar, ana adana sakamakon JSON a cikin ma’ajin gajimare.

// Don cikakkun misalai da fayilolin bayanai, da fatan za a je zuwa 
https://github.com/aspose-cells-cloud/aspose-cells-cloud-dotnet/

// Samu bayanan abokin ciniki daga https://dashboard.aspose.cloud/
string clientSecret = "4d84d5f6584160cbd91dba1fe145db14";
string clientID = "bb959721-5780-4be6-be35-ff5c3a6aa4a2";

// ƙirƙiri misalin CellsApi yayin wuce ClientID da ClientSecret
CellsApi cellsInstance = new CellsApi(clientID, clientSecret);

// sunan shigar da fayil CSV
string input_CSV = "source.csv";
// Sakamakon fayil JSON
string resultant_JSON = "resultant.json";

try
{
    // karanta abun ciki na shigar da fayil CSV
    var file = System.IO.File.OpenRead(input_CSV);

    // AjiyeOption abu yana bayyana tsarin fitarwa azaman JSON
    SaveOptions saveOptions = new SaveOptions()
    {
        SaveFormat = "JSON",
        ClearData = true
    };
    
    // Buƙatar adana littafin aiki
    PostWorkbookSaveAsRequest postworkbookSaveAsRequest = new PostWorkbookSaveAsRequest()
    {
        name = input_CSV,
        newfilename = resultant_JSON,
        isAutoFitRows = true,
        isAutoFitColumns = true
    };

    // fara aikin juyawa
    var response = cellsInstance.PostWorkbookSaveAs(postworkbookSaveAsRequest);

    // buga saƙon nasara idan tuba ya yi nasara
    if (response != null && response.Equals("OK"))
    {
        Console.WriteLine("The CSV to JSON conversion completed successfully !");
        Console.ReadKey();
    }
}
catch (Exception ex)
{
    Console.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace);
}
csv da json

Samfoti na CSV zuwa JSON.

Fitar da CSV zuwa JSON tare da Umarnin CURL

Ga waɗanda suka fi son ƙarfin layin umarni, samun nasarar CSV zuwa jujjuya JSON daidai yake da rashin daidaituwa tare da umarnin Aspose.Cells Cloud da cURL. Saki ikon sauƙaƙa yayin da muke jagorantar ku ta hanyoyin canza fayilolin CSV ɗinku zuwa tsarin JSON ta amfani da madaidaicin umarnin cURL da ingancin Aspose.Cells Cloud. Bugu da ƙari, wannan hanyar tana ba da hanya mai sauri da rubutu ga masu haɓakawa waɗanda ke godiya da ƙirar layin umarni.

Mataki na farko a wannan hanyar shine samar da alamar samun damar JWT ta amfani da umarni mai zuwa:

curl -v "https://api.aspose.cloud/connect/token" \
 -X POST \
 -d "grant_type=client_credentials&client_id=921363a8-b195-426c-85f7-7d458b112383&client_secret=2bf81fca2f3ca1790e405c904b94d233" \
 -H "Content-Type: application/x-www-form-urlencoded" \
 -H "Accept: application/json"

Yanzu, da fatan za a aiwatar da umarni mai zuwa don fitarwa CSV zuwa tsarin JSON. Bayan juyawa, sakamakon JSON ana adana shi a cikin ma’ajin gajimare.

curl -v "https://api.aspose.cloud/v3.0/cells/{sourceFile}/SaveAs?newfilename={resultantFile}&isAutoFitRows=true&isAutoFitColumns=true&checkExcelRestriction=false" \
-X POST \
-H "accept: application/json" \
-H "authorization: Bearer {accessToken}" \
-H "Content-Type: application/json" \
-d "{  \"SaveFormat\": \"JSON\",  \"ClearData\": true,  \"CreateDirectory\": true,  \"EnableHTTPCompression\": true,  \"RefreshChartCache\": true,  \"SortNames\": true,  \"ValidateMergedAreas\": true}"

Sauya ‘sourceFile’ tare da sunan shigar da fayil ɗin CSV da ke samuwa a cikin ma’ajiyar gajimare, ‘resultantFile’ tare da sunan sakamakon JSON fayil da za a ƙirƙira a cikin ma’ajiyar gajimare da ‘accessToken’ tare da alamar samun damar JWT da aka samar a sama.

Kammalawa

A ƙarshe, ko kun yarda da haɓakar haɓakawa tare da Aspose.Cells Cloud ta amfani da .NET SDK don ƙarin shirye-shirye da kuma m tsarin ko kuma layin umarni ta hanyar amfani da umarnin cURL don sauri, sauye-sauye na rubutun, tafiya daga CSV zuwa JSON bai taba kasancewa ba. m. Aspose.Cells Cloud yana ba da cikakkiyar bayani ga masu haɓakawa waɗanda ke neman haɗin kai maras kyau, yayin da umarnin cURL ke ba da madaidaiciya, madadin layin umarni.

Hanyoyin haɗi masu amfani

Labarai masu alaka

Muna ba da shawarar ziyartar shafukan yanar gizo masu zuwa: