LOGO OA教程 ERP教程 模切知识交流 PMS教程 CRM教程 开发文档 其他文档  
 
网站管理员

【ASP】读取写入 JSON for Classic ASP 类下载(aspjson1.19-master.zip)

admin
2024年12月12日 17:30 本文热度 2521

附件:aspjson1.19-master.zip

aspjson

Classic ASP JSON Class Reading/Writing

ASPJSON is a free to use project for generating and reading JSON data into a classic ASP object. The class can be used for reading a string of JSON data as well as writing JSON output from an AJAX file. Below are 2 simple examples of both.

Read Json Example:

Json内容:

{
  "firstName": "John",
  "lastName" : "Smith",
  "age"      : 25,
  "address"  :
  {
    "streetAddress": "21 2nd Street",
    "city"         : "New York",
    "state"        : "NY",
    "postalCode"   : "10021"
  },
  "phoneNumbers":
  [
    {
        "type"  : "home",
        "number": "212 555-1234"
      },
      {
        "type"  : "fax",
        "number": "646 555-4567"
    }
  ]
}

读取Json代码:

<%
Set oJSON = New aspJSON


'Load JSON string
oJSON.loadJSON(jsonstring)


'Get single value
Response.Write oJSON.data("firstName") & "<br>"
Response.Write oJSON.data("address").item("streetAddress") & "<br>"


'Loop through collection
For Each phonenr In oJSON.data("phoneNumbers")
    Set this = oJSON.data("phoneNumbers").item(phonenr)
    Response.Write _
    this.item("type") & ": " & _
    this.item("number") & "<br>"
Next


'Update/Add value
oJSON.data("firstName") = "James"


'Return json string
Response.Write oJSON.JSONoutput()
%>

Write Json Example:

Json内容:

{
  "familyName": "Smith",
  "familyMembers":
  [
    {
      "firstName": "John",
      "age": 41,
      "job": 
      {
        "function": "Webdeveloper",
        "salary": 70000
      }
    },
    {
      "firstName": "Suzan",
      "age": 38,
      "interests":
      [
        "Reading",
        "Tennis",
        "Painting"
      ]
    },
    {
      "firstName": "John Jr.",
      "age": 2.5
    }
  ]
}

写入Json代码:

<%
Set oJSON = New aspJSON
With oJSON.data
    .Add "familyName", "Smith"                      'Create value
    .Add "familyMembers", oJSON.Collection()
    With oJSON.data("familyMembers")
        .Add 0, oJSON.Collection()                  'Create unnamed object
        With .item(0)
            .Add "firstName", "John"
            .Add "age", 41
            .Add "job", oJSON.Collection()          'Create named object
            With .item("job")
                .Add "function", "Webdeveloper"
                .Add "salary", 70000
            End With
        End With
        .Add 1, oJSON.Collection()
        With .item(1)
            .Add "firstName", "Suzan"
            .Add "age", 38
            .Add "interests", oJSON.Collection()    'Create array
            With .item("interests")
                .Add 0, "Reading"
                .Add 1, "Tennis"
                .Add 2, "Painting"
            End With
        End With
        .Add 2, oJSON.Collection()
        With .item(2)
            .Add "firstName", "John Jr."
            .Add "age", 2.5
        End With
    End With
End With


Response.Write oJSON.JSONoutput()                   'Return json string

该文章在 2024/12/12 17:40:54 编辑过
点晴ERP是一款针对中小制造业的专业生产管理软件系统,系统成熟度和易用性得到了国内大量中小企业的青睐。
点晴PMS码头管理系统主要针对港口码头集装箱与散货日常运作、调度、堆场、车队、财务费用、相关报表等业务管理,结合码头的业务特点,围绕调度、堆场作业而开发的。集技术的先进性、管理的有效性于一体,是物流码头及其他港口类企业的高效ERP管理信息系统。
点晴WMS仓储管理系统提供了货物产品管理,销售管理,采购管理,仓储管理,仓库管理,保质期管理,货位管理,库位管理,生产管理,WMS管理系统,标签打印,条形码,二维码管理,批号管理软件。
点晴免费OA是一款软件和通用服务都免费,不限功能、不限时间、不限用户的免费OA协同办公管理系统。
Copyright 2010-2025 ClickSun All Rights Reserved