1

私はこれが何度も尋ねられたことを知っています。

しかし、正直なところ、多くの試みを行っても、解決策はうまくいきません。

ASP.Net 1.1で作業しているため、この.netレベルを処理できません。

そこで、私は多くの解決策を試しました。つまり、javascriptライブラリ、jqueryライブラリを使用してこれを行いました。

一部のツールは変換中ですが、<0>、<1><2>などを追加します。LoadXmlの実行中にフォーマットエラーがスローされます。

JSONオブジェクトをXMLに変換できる単純な関数または優れたライブラリが必要です。

ある場合は提案してください。

私はこれらをいくつか挙げてみました:

これにより、<0>、<1>、<2>の種類のタグを持つxmlが得られました。

これはまったく機能しませんでした。

編集

真ん中のJSONとXMLデータは巨大だったので削除しました:

JSON

"{\"CrashTestResult\":[[\"Crash Test Note\",\"Results based on a 35 MPH frontal crash and 38.5 MPH side crash.  Results are reported in a range of one to five stars, with five stars indicating the best crash protection for vehicles within \\"TIRES, P265/70R17 ALL-SEASON, BLACKWALL\",\"$0.00\"],[\"TIRES\",\"TIRES, P265/70R17 ON-/OFF-ROAD, WHITE OUTLINED-LETTER\",\"$125.00\"],[\"TIRES\",\"TIRES, P265/70R17 ON-/OFF-ROAD, BLACKWALL\",\"$150.00\"],[\"TIRES\",\"TIRES, P265/70R17 ALL-SEASON, WHITE OUTLINED-LETTER\",\"$125.00\"],[\"TIRES\",\"TIRES, P275/55R20 ALL-SEASON, BLACKWALL\",\"$0.00\"],[\"Drivetrain Years\",\"5\"],[\"Roadside Assistance Miles/km\",\"100,000\"],[\"Roadside Assistance Years\",\"5\"]],\"Wheel\":[\"WHEELS, 4 - 17\\\" X 7.5\\\" (43.2 CM X 19.1 CM) ALUMINUM, 5-SPOKE\",\"WHEELS, 4 - 17\\\" X 7.5\\\" (43.2 CM X 19.1 CM) ALUMINUM, 5-SPOKE\",\"WHEELS, 4 - 20\\\" X 8.5\\\" (50.8 CM X 21.6 CM) PAINTED ALUMINUM\"]}"

のようなXMLが欲しい

"<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n<VINDescription xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\r\n  <CrashTestResult xmlns=\"http://autoexact.com/VINDecoder/\">\r\n    <ArrayOfstring xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">\r\n      <string>Crash Test Note</string>\r\n      <string>Results based on a 35 MPH frontal crash and 38.5 MPH side crash.  Results are reported in a range of one to five stars, with five stars indicating the best crash protection for vehicles within the same weight class.  This test used driver and passenger belts and airbags.</string>\r\n    </ArrayOfstring>\r\n    <ArrayOfstring xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">\r\n      <string>Frontal Driver</string>\r\n      <string>* * * *</string>\r\n    </ArrayOfstring>\r\n    <ArrayOfstring xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">\r\n      <string>Frontal Passenger</string>\r\n      <string>* * * *</string>\r\n    </ArrayOfstring>\r\n<string>$2,755.00</string>\r\n    </ArrayOfstring>\r\n    <ArrayOfstring xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">\r\n      <string>CPOS PKG</string>\r\n      <string>28F CUSTOMER PREmas.microsoft.com/2003/10/Serialization/Arrays\">\r\n      <string>Basic Miles/km</string>\r\n      <string>36,000</string>\r\n    </ArrayOfstring>\r\n    <ArrayOfstring xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">\r\n      <string>Basic Years</string>\r\n      <string>3</string>\r\n    </ArrayOfstring>\r\n    <ArrayOfstring xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">\r\n      <string>Corrosion Miles/km</string>\r\n      <string>100,000</string>\r\n    </ArrayOfstring>\r\n    <ArrayOfstring xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">\r\n      <string>Corrosion Years</string>\r\n      <string>5</string>\r\n    </ArrayOfstring>\r\n    <ArrayOfstring xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">\r\n      <string>Drivetrain Miles/km</string>\r\n      <string>36,000</string>\r\n    </ArrayOfstring>\r\n    <ArrayOfstring xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">\r\n      <string>Drivetrain Note</string>\r\n      <string>Unlimited Years/Unlimited Miles for vehicles sold after 07/26/2007</string>\r\n    </ArrayOfstring>\r\n    <ArrayOfstring xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">\r\n      <string>Drivetrain Years</string>\r\n      <string>3</string>\r\n    </ArrayOfstring>\r\n  </Warranty>\r\n  <Wheel xmlns=\"http://autoexact.com/VINDecoder/\" />\r\n</VINDescription>"
4

1 に答える 1

0

こんにちは、このようなことを試してください。これは私のアプリケーションではうまく機能しますが、アプリケーション以外では使用していないので、役に立てば幸いです.

public string ParseJsonToXml(string sJsonObject)
    {
        DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(string));
        MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(sXMLJson));
        string sXMLDeSerialized = (string)ser.ReadObject(ms);
        ms.Close();
        return sXMLDeSerialized;
    }

xml をデータセットに、またはその逆に変換できるように、順番に文字列に解析します。

public DataSet ParseXmlToDataSet(string sXml)
    {      
        DataSet ds = new DataSet();
        StringReader sr = new StringReader(sXml);
        ds.ReadXml(sr);
        return ds;
    }

データセット使用の XML を取得するには

//ds is typeof(DataSet)
ds.GetXml();

注:これは、処理されたデータがどのように見えるかです

<DATA>
<TLOGIN>
    <USER>thabo.pali@za.pwc.com</USER>
    <PASSWORD>"Monday@01</PASSWORD>
</TLOGIN>
</DATA>

よろしくジョージ

于 2012-11-07T14:21:52.293 に答える