locked
Process JSONArray RRS feed

  • Question

  • User582566331 posted

    How ro process json array in webapi

    when pass

    "test:"[{"CartNo": "SISPL/CART/381 /2019-20",
    "Quantity": 1,
    "SerialNo": 1,
    "QuoteNo": "",
    "Rate": 12345,
    "CurrencyId": "INR"
    },

    {
    "CartNo": "SISPL/CART/381 /2019-20",
    "Quantity": 1,
    "SerialNo": 2,
    "QuoteNo": "",
    "Rate": 123455,
    "CurrencyId": "INR"
    }]

    using postman I am getting as

    {{
    "\"test:\"": {
    "{\"CartNo\": \"SISPL/CART/381 /2019-20\",\r\n\"Quantity\": 1,\r\n\"SerialNo\": 1,\r\n\"QuoteNo\": \"\",\r\n\"Rate\": 12345,\r\n\"CurrencyId\": \"INR\"\r\n},\r\n\r\n{\r\n\"CartNo\": \"SISPL/CART/381 /2019-20\",\r\n\"Quantity\": 1,\r\n\"SerialNo\": 2,\r\n\"QuoteNo\": \"\",\r\n\"Rate\": 123455,\r\n\"CurrencyId\": \"INR\"\r\n}]\r\n\r\n \r\n": ""
    }
    }}

    From here I need to extract each object

    Monday, September 2, 2019 3:49 AM

All replies

  • User753101303 posted

    Hi,

    Seems you want something such as :

    [
    {"CartNo": "SISPL/CART/381 /2019-20",
    "Quantity": 1,
    "SerialNo": 1,
    "QuoteNo": "",
    "Rate": 12345,
    "CurrencyId": "INR"
    },
    {
    "CartNo": "SISPL/CART/381 /2019-20",
    "Quantity": 1,
    "SerialNo": 2,
    "QuoteNo": "",
    "Rate": 123455,
    "CurrencyId": "INR"
    }
    ]

    which is an array of objects with those properties. See for example http://json.org/

    Do you really have to use the JsonArray class. IMO just use strongly typed class whenever possible and let JS and ASP.NET to handle serialization/deserialization for you...

    Monday, September 2, 2019 9:53 AM
  • User61956409 posted

    Hi sweetyPaul,

    Please clarify more about the question and your requirement, so that we can understand it better.

    For example, where you want to extract each object/item based on that array, on JavaScript client side or C#?

    With Regards,

    Fei Han

    Tuesday, September 3, 2019 1:56 AM