Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Magazin de îmbrăcăminte
    • Magazin de Mobilă
    • Magazin alimentar
    • Magazin de materiale de construcții
    • Magazin de jucării
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Distribuitor de băuturi
    • Hotel
    Proprietate imobiliara
    • Real Estate Agency
    • Firmă de Arhitectură
    • Construcție
    • Estate Managament
    • Grădinărit
    • Asociația Proprietarilor de Proprietăți
    Consultanta
    • Firma de Contabilitate
    • Partener Odoo
    • Agenție de marketing
    • Law firm
    • Atragere de talente
    • Audit & Certification
    Producție
    • Textil
    • Metal
    • Mobilier
    • Mâncare
    • Brewery
    • Cadouri corporate
    Health & Fitness
    • Club Sportiv
    • Magazin de ochelari
    • Centru de Fitness
    • Wellness Practitioners
    • Farmacie
    • Salon de coafură
    Trades
    • Handyman
    • IT Hardware and Support
    • Asigurare socială de stat
    • Cizmar
    • Servicii de curățenie
    • HVAC Services
    Altele
    • Organizație nonprofit
    • Agenție de Mediu
    • Închiriere panouri publicitare
    • Fotografie
    • Închiriere biciclete
    • Asigurare socială
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

Get Value From JSON code

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
pythonjson
3 Răspunsuri
13387 Vizualizări
Imagine profil
abdelwahed chiheb

Hi evryone,

i'm calling a python function from a javascript code, so i'm passing the record with json format. i want to get the value of some fileds from the JSON code. How can i do this ?

image description

0
Imagine profil
Abandonează
Imagine profil
abdelwahed chiheb
Autor Cel mai bun răspuns

Hi Martin, thank's .... I tried this code and it work :D

def delete_reserve(self, cr, uid, ids , record,this):
    to_json = json.dumps(record,separators=(','':'))
    data_json = json.loads(to_json)
    wg_product = data_json['attributes']['product_id']
    wg_qty_uos = data_json['attributes']['product_uos_qty']
0
Imagine profil
Abandonează
Martin

Glad to help. Pity I missed the karma points by deleting too fast, duh.

Imagine profil
Martin
Cel mai bun răspuns

Heh!

I deleted my answer because I noticed you wanted JavaScript. You'll see both my earlier versions below:

Improving my old Python answer (below), you may find it far nicer to work with json.loads() with built in conversion to a dot separated namespace object, like this :

data_json = json.loads(
         to_json
       , object_hook=lambda d: namedtuple('X', d.keys())(*d.values()))
wg_product = data_json.attributes.product_id
wg_qty_uos = data_json.attributes.product_uos_qty

If you still want JavaScript as you originally asked . . .

  <!DOCTYPE html>
  <html>
  <meta charset="UTF-8">
  <body>

  <p id="rslt">Result here.</p>

  <p id="alt">Alternate result here.</p>

  <button type="button" onclick="tryIt()">Try</button>

  </body>

  <script>

  var jsonGlossary = "{";
  jsonGlossary +=    "  \"glossary\": {";
  jsonGlossary +=    "    \"title\": \"example glossary\",";
  jsonGlossary +=    "    \"GlossDiv\": {";
  jsonGlossary +=    "      \"title\": \"S\",";
  jsonGlossary +=    "      \"GlossList\": {";
  jsonGlossary +=    "        \"GlossEntry\": {";
  jsonGlossary +=    "          \"ID\": \"SGML\",";
  jsonGlossary +=    "          \"SortAs\": \"SGML\",";
  jsonGlossary +=    "          \"GlossTerm\": \"Standard Generalized Markup Language\",";
  jsonGlossary +=    "          \"Acronym\": \"SGML\",";
  jsonGlossary +=    "          \"Abbrev\": \"ISO 8879:1986\",";
  jsonGlossary +=    "          \"GlossDef\": {";
  jsonGlossary +=    "            \"para\": \"A meta-markup language, used to create markup languages such as DocBook.\",";
  jsonGlossary +=    "            \"GlossSeeAlso\": [\"GML\", \"XML\"]";
  jsonGlossary +=    "          },";
  jsonGlossary +=    "          \"GlossSee\": \"markup\"";
  jsonGlossary +=    "        }";
  jsonGlossary +=    "      }";
  jsonGlossary +=    "    }";
  jsonGlossary +=    "  }";
  jsonGlossary +=    "}";



  function tryIt()
  {
        obj = JSON.parse(jsonGlossary);
        document.getElementById("rslt").innerHTML=obj['glossary']['GlossDiv']['GlossList']['GlossEntry']['GlossTerm'];
        document.getElementById("alt").innerHTML=obj.glossary.GlossDiv.GlossList.GlossEntry.GlossDef.para;
  }
  </script>

  </html>

Not that it matters now, but this was the first answer (that I deleted while you were answering).

  #!/usr/bin/python
  # -*- coding: utf-8 -*-
  #
  from json import loads

  jsonGlossary = '{'
  jsonGlossary += '  "glossary": {'
  jsonGlossary += '    "title": "example glossary",'
  jsonGlossary += '    "GlossDiv": {'
  jsonGlossary += '      "title": "S",'
  jsonGlossary += '      "GlossList": {'
  jsonGlossary += '        "GlossEntry": {'
  jsonGlossary += '          "ID": "SGML",'
  jsonGlossary += '          "SortAs": "SGML",'
  jsonGlossary += '          "GlossTerm": "Standard Generalized Markup Language",'
  jsonGlossary += '          "Acronym": "SGML",'
  jsonGlossary += '          "Abbrev": "ISO 8879:1986",'
  jsonGlossary += '          "GlossDef": {'
  jsonGlossary += '            "para": "A meta-markup language, used to create markup languages such as DocBook.",'
  jsonGlossary += '            "GlossSeeAlso": ["GML", "XML"]'''
  jsonGlossary += '          },'
  jsonGlossary += '          "GlossSee": "markup"'
  jsonGlossary += '        }'
  jsonGlossary += '      }'
  jsonGlossary += '    }'
  jsonGlossary += '  }'
  jsonGlossary += '}'

  print jsonGlossary

  print ' #A - - '
  dictGlossary = loads (jsonGlossary)

  print dictGlossary

  print ' #B - - '
  print dictGlossary['glossary']['GlossDiv']['GlossList']['GlossEntry']['GlossDef']['para']
0
Imagine profil
Abandonează
Imagine profil
Martin
Cel mai bun răspuns

Hi,

Try something like this :

  #!/usr/bin/python
  # -*- coding: utf-8 -*-
  #
  from json import loads

  jsonGlossary = '{'
  jsonGlossary += '  "glossary": {'
  jsonGlossary += '    "title": "example glossary",'
  jsonGlossary += '    "GlossDiv": {'
  jsonGlossary += '      "title": "S",'
  jsonGlossary += '      "GlossList": {'
  jsonGlossary += '        "GlossEntry": {'
  jsonGlossary += '          "ID": "SGML",'
  jsonGlossary += '          "SortAs": "SGML",'
  jsonGlossary += '          "GlossTerm": "Standard Generalized Markup Language",'
  jsonGlossary += '          "Acronym": "SGML",'
  jsonGlossary += '          "Abbrev": "ISO 8879:1986",'
  jsonGlossary += '          "GlossDef": {'
  jsonGlossary += '            "para": "A meta-markup language, used to create markup languages such as DocBook.",'
  jsonGlossary += '            "GlossSeeAlso": ["GML", "XML"]'''
  jsonGlossary += '          },'
  jsonGlossary += '          "GlossSee": "markup"'
  jsonGlossary += '        }'
  jsonGlossary += '      }'
  jsonGlossary += '    }'
  jsonGlossary += '  }'
  jsonGlossary += '}'

  print jsonGlossary

  print ' #A - - '
  dictGlossary = loads (jsonGlossary)

  print dictGlossary

  print ' #B - - '
  print dictGlossary['glossary']['GlossDiv']['GlossList']['GlossEntry']['GlossDef']['para']

Your output should look this :

{  "glossary": {    "title": "example glossary",    "GlossDiv": {      "title  . . . 
 #A - - 
{u'glossary': {u'GlossDiv': {u'GlossList': {u'GlossEntry': {u'GlossDe . . . 
 #B - - 
A meta-markup language, used to create markup languages such as DocBook.
0
Imagine profil
Abandonează
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
How to get a value from json?
python json odoo9.0
Imagine profil
0
ian. 16
4826
new python env
python
Imagine profil
0
mar. 25
2271
What means "Too many values to unpack" message? Rezolvat
python
Imagine profil
Imagine profil
Imagine profil
Imagine profil
Imagine profil
4
apr. 24
175719
have no data in screen. read data in my own module from different model
python
Imagine profil
0
dec. 23
2923
How to insert value to a one2many field in table with create method? Rezolvat
python
Imagine profil
Imagine profil
Imagine profil
Imagine profil
Imagine profil
5
iul. 25
231907
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now