Announcement

Collapse
No announcement yet.

saving a JSON string

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    saving a JSON string

    In a custom module I am generating some JSON to MvCall to a service. The request and response are working perfectly.
    I'd like to save that submitted JSON string in the order to a custom order field.

    Not getting the results I am expecting. This is what is being saved in the COF:

    {
    "quote_id": "f07a71a9-a953-4b41-9a72-56a6d2bc288d",
    "source_order_id": "1590",
    etc...
    This is what I am expecting. It's also what I see when doing an MvEval to the page.

    {
    "quote_id": "f07a71a9-a953-4b41-9a72-56a6d2bc288d",
    "source_order_id": "1590",
    etc...
    The string is currently being saved using the Write_Order() function on the INVC template. That's what is spec'd right now.

    I have tried all the encodejavascriptstring/encoding/decoding functions that would make sense in the module and the SMT functions for writing that value to the COF.

    Is it possible and/or What am I missing to get the desired result?

    Thanks,

    Scott


    Need to offer Shipping Insurance?
    Interactive Design Solutions https://www.myids.net
    MivaMerchant Business Partner | Certified MivaMerchant Web Developer
    Competitive Rates, Custom Modules and Integrations, Store Integration
    AutoBaskets|Advanced Waitlist Integration|Ask about Shipping Insurance Integration
    My T-shirt Collection is mostly MivaCon T-shirts!!

    #2
    Have you verified that is what was actually being saved in the DB and not what is being output when re-displayed. The Custom Fields module doesn't encode the data on input or output. So you are either passing an encoded value when it is being saved or the you are seeing the encoded value when the value is output in runtime.
    David Carver
    Miva, Inc. | Software Developer

    Comment


      #3
      Try mveval inside a pre tag or a textarea so you can make sure you are seeing what you think you're seeing. The browser might be changing " into " for your debug preview.

      Sometimes using mvcapture on a mveval before saving will translate characters into what you want as well.

      I've never seeing write_order(...) or any other functions automatically convert stuff the way you're describing, so examining that data in various ways before saving might give you the answer.

      M.A.D.* since 1997

      http://www.scotsscripts.com

      *miva application developers

      Comment


        #4
        Sounds like I shouldn't need to encode or decode anything?

        I saw the code listed in Order Processing as I've illustrated, viewing the CF Group or displaying the CF in Batch Edit, when I hadn't considered any encoding at all. I had not checked the string in the DB at that point. I will do that. But that is where I initially found this issue.

        I am creating the JSON string using MvCapture in the module. Would I need to MvCapture the Eval of that captured string? Then write that new variable into the Custom field?

        The operational part is to be able to view/copy/paste the JSON string from the Order Processing Admin screens.

        Scott
        Need to offer Shipping Insurance?
        Interactive Design Solutions https://www.myids.net
        MivaMerchant Business Partner | Certified MivaMerchant Web Developer
        Competitive Rates, Custom Modules and Integrations, Store Integration
        AutoBaskets|Advanced Waitlist Integration|Ask about Shipping Insurance Integration
        My T-shirt Collection is mostly MivaCon T-shirts!!

        Comment


          #5
          I'd say export the initial string to see exactly what is coming in. If it's attribute encoded then you decode before saving. If it's not encoded, then double check the string at every point where it could change in your code. At least, those are the steps I'd take in this situation.
          M.A.D.* since 1997

          http://www.scotsscripts.com

          *miva application developers

          Comment


            #6
            I recently ran into a similar situation:

            When json is passed through http it needs to be sent as a string not as an object - JSON.stringify().

            The json is returned from the server in the response.body.

            The json key:values cannot contain special characters such as double quotes so it is mostly likely entity encoded, attribute encoded or base64 encoded.

            mvte is used for html entites, mvta is used for uri and base64 is used for anything like images.

            MvCall receives the json as a string and rebuilds it in chunks and remains as a string.

            To change the json to an object use JSON.parse().

            I'm not sure if that is what is going on but I hope it helps.
            http://www.alphabetsigns.com/

            Comment

            Working...
            X