Как преобразовать объект json в желаемый формат XML в С# ASP.Net?

Вопрос:

Привет, я конвертирую свой json Object в строку. Но все атрибуты узлов преобразуются в узлы.

Я хочу, чтобы строка была в правильном формате, пожалуйста, расскажите мне, как это возможно.

Json Object:

                var RuleObj = {

"Rule": {
"RuleTypeID": {
"RuleTypeValue": 105,
"RWD_DEFAULT_SERVER_COMMISSION_PERCENTAGE": 5.75,
"RWD_DEFAULT_SERVER_FIXED_COMMISSION_IN_PAISE": 123,
"ME_DEFAULT_COMMISSION_PERCENTAGE": 5.75,
"ME_DEFAULT_FIXED_COMMISSION_IN_PAISE": 123,
"MAX_RULE_APPLICABLITY_PER_CARD_COUNT": 123,
"Schemes": {
"Schema": {
"MIN_BIN": 123,
"MAX_BIN": 999,
"RULE_START_HOUR": "2012-12-13T12:12:12",
"RULE_END_HOUR": "2017-12-13T12:12:12",
"APPLICABLE_DAYS_BITMAP": 127,
"MIN_AMOUNT": 123,
"MAX_AMOUNT": 999,
"RWD_SERVER_COMMISSION_PERCENTAGE": 5.75,
"RWD_SERVER_FIXED_COMMISSION_IN_PAISE": 123,
"ME_COMMISSION_PERCENTAGE": 5.75,
"ME_FIXED_COMMISSION_IN_PAISE": 123,
"INSTANT_DISCOUNT_PERCENTAGE_ISSUER": 5.7513433,
"INSTANT_DISCOUNT_FIXED_DISCOUNT_ISSUER_PAISE": 123,
"INSTANT_DISCOUNT_PERCENTAGE_MERCHANT": 5.75,
"INSTANT_DISCOUNT_FIXED_DISCOUNT_MERCHANT_PAISE": 123,
"MAX_INSTANT_DISCOUNT_AMOUNT_PAISE": 123,
"MIN_INSTANT_DISCOUNT_AMOUNT_PAISE": 123,
"INSTANT_DISCOUNT_STATIC_TEXT_HEADER": "str1234",
"INSTANT_DISCOUNT_STATIC_TEXT_FOOTER": "str1234",
"INSTANT_DISCOUNT_GRAPHIC_IMAGE_ID_HEADER": 123,
"INSTANT_DISCOUNT_GRAPHIC_IMAGE_ID_FOOTER": 123,
"NX_REWARD_MULTIPLIER": 123,
"NX_REWARD_FIXED_REWARD_POINTS": 123,
"MAX_REWARDED_POINTS": 123,
"MIN_REWARDED_POINTS": 123,
"NX_REWARD_STATIC_TEXT_HEADER": "str1234",
"NX_REWARD_STATIC_TEXT_FOOTER": "str1234",
"NX_REWARD_GRAPHIC_IMAGE_ID_HEADER": 123,
"NX_REWARD_GRAPHIC_IMAGE_ID_FOOTER": 123,
"EMI_MONTHS_BITMAP": 128,
"USE_ORIGINAL_AMOUNT_FOR_EMI_APPLICABILITY": 23,
"MAX_REDEEMED_COUNT": 123,
"MAX_SCHEMA_APPLICABLITY_PER_CARD_COUNT": 123,
"EMI_PARAMETERS": {
"EMI_PARAMETER": {
"EMI_TENURE_MONTH": "03",
"CUSTOMER_PROCESSING_FEE_PERCENTAGE": 5.75,
"SUBVENTION_PAYABLE_TO_ISSUER_PERCENTAGE": 5.75,
"INTEREST_RATE_PERCENTAGE": 5.75,
"MERCHANT_OFFERED_DISCOUNT_CASHBACK_PERCENTAGE": 5.75,
"FIXED_MERCHANT_OFFERED_DISCOUNT_CASHBACK_AMOUNT_PAISE": 123,
"MAX_MERCHANT_OFFERED_DISCOUNT_CASHBACK_AMOUNT_PAISE": 123,
"MIN_MERCHANT_OFFERED_DISCOUNT_CASHBACK_AMOUNT_PAISE": 123,
"ISSUER_OFFERED_DISCOUNT_CASHBACK_PERCENTAGE": 5.75,
"FIXED_ISSUER_OFFERED_DISCOUNT_CASHBACK_AMOUNT_PAISE": 123,
"MAX_ISSUER_OFFERED_DISCOUNT_CASHBACK_AMOUNT_PAISE": 123,
"MIN_ISSUER_OFFERED_DISCOUNT_CASHBACK_AMOUNT_PAISE": 123,
"CASHBACK_TYPE": 12,
"STATIC_TEXT_HEADER": "str1234",
"STATIC_TEXT_FOOTER": "str1234",
"GRAPHIC_IMAGE_ID_HEADER": 123,
"GRAPHIC_IMAGE_ID_FOOTER": 123,
"PAYMENT_HOLIDAY": {
"MIN_BIN": 123,
"MAX_BIN": 100,
"MIN_AMOUNT": 123,
"MAX_AMOUNT": 999,
"HOLIDAY_PERIOD_DAYS": 123
}
}
}
}
}
}
}


};
var jsonText = $.toJSON(jsEmp);

Передача jsonText с клиентской стороны на серверную сторону в Asp.Net с использованием Jquery и Ajax.

На стороне сервера я преобразовываю этот объект в строку следующим образом:

 string json = new JavaScriptSerializer().Serialize(jsonParam);
XmlDocument doc = JsonConvert.DeserializeXmlNode(json,"RuleSchema");
string strTemp = doc.InnerXml;
string strTempInnserText = doc.InnerText;

Но когда я вижу значение strTemp, оно будет следующим.

     <RuleSchema>
<Rule>
<RuleTypeID>
<RuleTypeValue>105</RuleTypeValue>
<RWD_DEFAULT_SERVER_COMMISSION_PERCENTAGE>5.75</RWD_DEFAULT_SERVER_COMMISSION_PERCENTAGE>
<RWD_DEFAULT_SERVER_FIXED_COMMISSION_IN_PAISE>123</RWD_DEFAULT_SERVER_FIXED_COMMISSION_IN_PAISE>
<ME_DEFAULT_COMMISSION_PERCENTAGE>5.75</ME_DEFAULT_COMMISSION_PERCENTAGE>
<ME_DEFAULT_FIXED_COMMISSION_IN_PAISE>123</ME_DEFAULT_FIXED_COMMISSION_IN_PAISE>
<MAX_RULE_APPLICABLITY_PER_CARD_COUNT>123</MAX_RULE_APPLICABLITY_PER_CARD_COUNT>
<Schemes>
<Schema>
<MIN_BIN>123</MIN_BIN>
<MAX_BIN>999</MAX_BIN>
<RULE_START_HOUR>2012-12-13T12:12:12</RULE_START_HOUR>
<RULE_END_HOUR>2017-12-13T12:12:12</RULE_END_HOUR>
<APPLICABLE_DAYS_BITMAP>127</APPLICABLE_DAYS_BITMAP>
<MIN_AMOUNT>123</MIN_AMOUNT>
<MAX_AMOUNT>999</MAX_AMOUNT>
<RWD_SERVER_COMMISSION_PERCENTAGE>5.75</RWD_SERVER_COMMISSION_PERCENTAGE>
<RWD_SERVER_FIXED_COMMISSION_IN_PAISE>123</RWD_SERVER_FIXED_COMMISSION_IN_PAISE>
<ME_COMMISSION_PERCENTAGE>5.75</ME_COMMISSION_PERCENTAGE>
<ME_FIXED_COMMISSION_IN_PAISE>123</ME_FIXED_COMMISSION_IN_PAISE>
<INSTANT_DISCOUNT_PERCENTAGE_ISSUER>5.7513433</INSTANT_DISCOUNT_PERCENTAGE_ISSUER>
<INSTANT_DISCOUNT_FIXED_DISCOUNT_ISSUER_PAISE>123</INSTANT_DISCOUNT_FIXED_DISCOUNT_ISSUER_PAISE>
<INSTANT_DISCOUNT_PERCENTAGE_MERCHANT>5.75</INSTANT_DISCOUNT_PERCENTAGE_MERCHANT>
<INSTANT_DISCOUNT_FIXED_DISCOUNT_MERCHANT_PAISE>123</INSTANT_DISCOUNT_FIXED_DISCOUNT_MERCHANT_PAISE>
<MAX_INSTANT_DISCOUNT_AMOUNT_PAISE>123</MAX_INSTANT_DISCOUNT_AMOUNT_PAISE>
<MIN_INSTANT_DISCOUNT_AMOUNT_PAISE>123</MIN_INSTANT_DISCOUNT_AMOUNT_PAISE>
<INSTANT_DISCOUNT_STATIC_TEXT_HEADER>str1234</INSTANT_DISCOUNT_STATIC_TEXT_HEADER>
<INSTANT_DISCOUNT_STATIC_TEXT_FOOTER>str1234</INSTANT_DISCOUNT_STATIC_TEXT_FOOTER>
<INSTANT_DISCOUNT_GRAPHIC_IMAGE_ID_HEADER>123</INSTANT_DISCOUNT_GRAPHIC_IMAGE_ID_HEADER>
<INSTANT_DISCOUNT_GRAPHIC_IMAGE_ID_FOOTER>123</INSTANT_DISCOUNT_GRAPHIC_IMAGE_ID_FOOTER>
<NX_REWARD_MULTIPLIER>123</NX_REWARD_MULTIPLIER>
<NX_REWARD_FIXED_REWARD_POINTS>123</NX_REWARD_FIXED_REWARD_POINTS>
<MAX_REWARDED_POINTS>123</MAX_REWARDED_POINTS>
<MIN_REWARDED_POINTS>123</MIN_REWARDED_POINTS>
<NX_REWARD_STATIC_TEXT_HEADER>str1234</NX_REWARD_STATIC_TEXT_HEADER>
<NX_REWARD_STATIC_TEXT_FOOTER>str1234</NX_REWARD_STATIC_TEXT_FOOTER>
<NX_REWARD_GRAPHIC_IMAGE_ID_HEADER>123</NX_REWARD_GRAPHIC_IMAGE_ID_HEADER>
<NX_REWARD_GRAPHIC_IMAGE_ID_FOOTER>123</NX_REWARD_GRAPHIC_IMAGE_ID_FOOTER>
<EMI_MONTHS_BITMAP>128</EMI_MONTHS_BITMAP>
<USE_ORIGINAL_AMOUNT_FOR_EMI_APPLICABILITY>23</USE_ORIGINAL_AMOUNT_FOR_EMI_APPLICABILITY>
<MAX_REDEEMED_COUNT>123</MAX_REDEEMED_COUNT>
<MAX_SCHEMA_APPLICABLITY_PER_CARD_COUNT>123</MAX_SCHEMA_APPLICABLITY_PER_CARD_COUNT>
<EMI_PARAMETERS>
<EMI_PARAMETER>
<EMI_TENURE_MONTH>03</EMI_TENURE_MONTH>
<CUSTOMER_PROCESSING_FEE_PERCENTAGE>5.75</CUSTOMER_PROCESSING_FEE_PERCENTAGE>
<SUBVENTION_PAYABLE_TO_ISSUER_PERCENTAGE>5.75</SUBVENTION_PAYABLE_TO_ISSUER_PERCENTAGE>
<INTEREST_RATE_PERCENTAGE>5.75</INTEREST_RATE_PERCENTAGE>
<MERCHANT_OFFERED_DISCOUNT_CASHBACK_PERCENTAGE>5.75</MERCHANT_OFFERED_DISCOUNT_CASHBACK_PERCENTAGE>
<FIXED_MERCHANT_OFFERED_DISCOUNT_CASHBACK_AMOUNT_PAISE>123</FIXED_MERCHANT_OFFERED_DISCOUNT_CASHBACK_AMOUNT_PAISE>
<MAX_MERCHANT_OFFERED_DISCOUNT_CASHBACK_AMOUNT_PAISE>123</MAX_MERCHANT_OFFERED_DISCOUNT_CASHBACK_AMOUNT_PAISE>
<MIN_MERCHANT_OFFERED_DISCOUNT_CASHBACK_AMOUNT_PAISE>123</MIN_MERCHANT_OFFERED_DISCOUNT_CASHBACK_AMOUNT_PAISE>
<ISSUER_OFFERED_DISCOUNT_CASHBACK_PERCENTAGE>5.75</ISSUER_OFFERED_DISCOUNT_CASHBACK_PERCENTAGE>
<FIXED_ISSUER_OFFERED_DISCOUNT_CASHBACK_AMOUNT_PAISE>123</FIXED_ISSUER_OFFERED_DISCOUNT_CASHBACK_AMOUNT_PAISE>
<MAX_ISSUER_OFFERED_DISCOUNT_CASHBACK_AMOUNT_PAISE>123</MAX_ISSUER_OFFERED_DISCOUNT_CASHBACK_AMOUNT_PAISE>
<MIN_ISSUER_OFFERED_DISCOUNT_CASHBACK_AMOUNT_PAISE>123</MIN_ISSUER_OFFERED_DISCOUNT_CASHBACK_AMOUNT_PAISE>
<CASHBACK_TYPE>12</CASHBACK_TYPE>
<STATIC_TEXT_HEADER>str1234</STATIC_TEXT_HEADER>
<STATIC_TEXT_FOOTER>str1234</STATIC_TEXT_FOOTER>
<GRAPHIC_IMAGE_ID_HEADER>123</GRAPHIC_IMAGE_ID_HEADER>
<GRAPHIC_IMAGE_ID_FOOTER>123</GRAPHIC_IMAGE_ID_FOOTER>
<PAYMENT_HOLIDAY>
<MIN_BIN>123</MIN_BIN>
<MAX_BIN>100</MAX_BIN>
<MIN_AMOUNT>123</MIN_AMOUNT>
<MAX_AMOUNT>999</MAX_AMOUNT>
<HOLIDAY_PERIOD_DAYS>123</HOLIDAY_PERIOD_DAYS>
</PAYMENT_HOLIDAY>
</EMI_PARAMETER>
</EMI_PARAMETERS>
</Schema>
</Schemes>
</RuleTypeID>
</Rule>
</RuleSchema>

Он должен прийти в таком формате:

    <RuleSchema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="RulesSchema.xsd">
<Rule>
<RuleTypeID RuleTypeValue="105"
RWD_DEFAULT_SERVER_COMMISSION_PERCENTAGE="5.75"
RWD_DEFAULT_SERVER_FIXED_COMMISSION_IN_PAISE="123"
ME_DEFAULT_COMMISSION_PERCENTAGE="5.75"
ME_DEFAULT_FIXED_COMMISSION_IN_PAISE="123"
MAX_RULE_APPLICABLITY_PER_CARD_COUNT="123">
<Schemes>
<Schema MIN_BIN="123" MAX_BIN="999"
RULE_START_HOUR="2012-12-13T12:12:12"
RULE_END_HOUR="2017-12-13T12:12:12"
APPLICABLE_DAYS_BITMAP="127"
MIN_AMOUNT="123" MAX_AMOUNT="999"
RWD_SERVER_COMMISSION_PERCENTAGE="5.75"
RWD_SERVER_FIXED_COMMISSION_IN_PAISE="123"
ME_COMMISSION_PERCENTAGE="5.75"
ME_FIXED_COMMISSION_IN_PAISE="123"
INSTANT_DISCOUNT_PERCENTAGE_ISSUER="5.7513433"
INSTANT_DISCOUNT_FIXED_DISCOUNT_ISSUER_PAISE="123"
INSTANT_DISCOUNT_PERCENTAGE_MERCHANT="5.75"
INSTANT_DISCOUNT_FIXED_DISCOUNT_MERCHANT_PAISE="123"
MAX_INSTANT_DISCOUNT_AMOUNT_PAISE="123"
MIN_INSTANT_DISCOUNT_AMOUNT_PAISE="123"
INSTANT_DISCOUNT_STATIC_TEXT_HEADER="str1234"
INSTANT_DISCOUNT_STATIC_TEXT_FOOTER="str1234"
INSTANT_DISCOUNT_GRAPHIC_IMAGE_ID_HEADER="123"
INSTANT_DISCOUNT_GRAPHIC_IMAGE_ID_FOOTER="123"
NX_REWARD_MULTIPLIER="123"
NX_REWARD_FIXED_REWARD_POINTS="123"
MAX_REWARDED_POINTS="123"
MIN_REWARDED_POINTS="123"
NX_REWARD_STATIC_TEXT_HEADER="str1234"
NX_REWARD_STATIC_TEXT_FOOTER="str1234"
NX_REWARD_GRAPHIC_IMAGE_ID_HEADER="123"
NX_REWARD_GRAPHIC_IMAGE_ID_FOOTER="123"
EMI_MONTHS_BITMAP="128"
USE_ORIGINAL_AMOUNT_FOR_EMI_APPLICABILITY="23"
MAX_REDEEMED_COUNT="123"
MAX_SCHEMA_APPLICABLITY_PER_CARD_COUNT="123">
<EMI_PARAMETERS>
<EMI_PARAMETER
EMI_TENURE_MONTH="03"
CUSTOMER_PROCESSING_FEE_PERCENTAGE="5.75"
SUBVENTION_PAYABLE_TO_ISSUER_PERCENTAGE="5.75"
INTEREST_RATE_PERCENTAGE="5.75"
MERCHANT_OFFERED_DISCOUNT_CASHBACK_PERCENTAGE="5.75"
FIXED_MERCHANT_OFFERED_DISCOUNT_CASHBACK_AMOUNT_PAISE="123"
MAX_MERCHANT_OFFERED_DISCOUNT_CASHBACK_AMOUNT_PAISE="123"
MIN_MERCHANT_OFFERED_DISCOUNT_CASHBACK_AMOUNT_PAISE="123"
ISSUER_OFFERED_DISCOUNT_CASHBACK_PERCENTAGE="5.75"
FIXED_ISSUER_OFFERED_DISCOUNT_CASHBACK_AMOUNT_PAISE="123"
MAX_ISSUER_OFFERED_DISCOUNT_CASHBACK_AMOUNT_PAISE="123"
MIN_ISSUER_OFFERED_DISCOUNT_CASHBACK_AMOUNT_PAISE="123"
CASHBACK_TYPE="12"
STATIC_TEXT_HEADER="str1234"
STATIC_TEXT_FOOTER="str1234"
GRAPHIC_IMAGE_ID_HEADER="123"
GRAPHIC_IMAGE_ID_FOOTER="123">
<PAYMENT_HOLIDAY
MIN_BIN="123"
MAX_BIN="100"
MIN_AMOUNT="123"
MAX_AMOUNT="999"
HOLIDAY_PERIOD_DAYS="123" />
</EMI_PARAMETER>
</EMI_PARAMETERS>
</Schema>
</Schemes>
</RuleTypeID>
</Rule>
</RuleSchema>

Скажите, пожалуйста, если я делаю что-то неправильно или есть какой-то другой способ добиться этого.

Лучший ответ:

Привет Следующим путем Мы можем достичь этого, Нам нужно добавить атрибуты @bejust.

        string json = @"{ '?xml': { '@version': '1.0', '@standalone': 'no' }, 'root': { 'person': [ { '@id': '1',
     'name': 'Alan', 'url': 'http://www.google.com' }, { '@id': '2', 'name': 'Louis', 
     'url': 'http://www.yahoo.com' } ] } }";  
XmlDocument doc = (XmlDocument)JsonConvert.DeserializeXmlNode(json); 

Это XML.

  <?xml version="1.0" standalone="no"?> 
    <root> 
    <person id="1"> 
    <name>Alan</name>
     <url>http://www.google.com</url>
         </person>
     <person id="2">
         <name>Louis</name> 
    <url>http://www.yahoo.com</url>
 </person> </root>

Оцените статью
TechArks.Ru
Добавить комментарий