JSON Parse error: Unexpected EOF occurred when trying to change value

JSON Parse error: Unexpected EOF occurred when trying to change value

我在我的 react-native-expo 应用程序中使用 NodeJS express 作为后端和 mongo atlas。我已将数据存储在我的 TicketScreen.js 中,但是当我尝试更改 AllTicketScreen.js 中的数据值时发生错误。

谁能告诉我为什么我不能更改我的 AllTicketScreen.js 中的值,我该怎么做?

TicketScreen.js

handleSubmit = () => {
        fetch("http://d5c2ae1dd6ff.ngrok.io/send-data", {
            method: "POST",
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({
                name: name,
                request: request,
                subject: subject,
                category: category,
                priority: priority,
                desc: desc,
                location: location,
                status: "Open"
            })
        })
        .then(res => res.json())
        .then(data => {
            navigation.navigate("Home")
        })
    }

全部TicketScreen.js

useEffect(() => {
        readData()
    }, [])

    onRefresh = () => {
        setRefreshing(true);
        readData();
    }

    readData = () => {
        fetch("http://d5c2ae1dd6ff.ngrok.io/")
            .then(res => res.json())
            .then(results => {
                setData(results)
                setRefreshing(false)
            })
            .catch((error) => {
                console.error(error);
            });
    }

    ticketClosed = () => {
        fetch("http://d5c2ae1dd6ff.ngrok.io/closed", {
            method: "POST",
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({
                id: data._id,
                name: data.name,
                request: data.request,
                subject: data.subject,
                category: data.category,
                priority: data.priority,
                desc: data.desc,
                location: data.location,
                status: "Closed"
            })
        })
        .then(res => res.json())
        .then(data => {
            navigation.navigate("Home")
        })
        .catch(err => {
            console.log("Error occurred: " + err);
        })
    }

<ScrollView refreshControl={
                <RefreshControl
                    refreshing={refreshing}
                    onRefresh={onRefresh}
                />
            }>
                <View>
                    {data.length > 0 && (
                        <List.AccordionGroup>
                            {
                                data.map((rowData, index) => (

                                    <List.Accordion title={rowData.subject} key={rowData._id} id={rowData._id} style={{ marginBottom: 10, backgroundColor: 'white', marginTop: 10, }}>
                                        <View style={{ padding: 20, backgroundColor: '#FAFAFA' }}>
                                            <Text style={styles.ticketDescription}> Project Name:  </Text><List.Item title={rowData.name} />
                                            <Text style={styles.ticketDescription}> Requested By:  </Text><List.Item title={rowData.request} />
                                            <Text style={styles.ticketDescription}> Category:  </Text><List.Item title={rowData.category} />
                                            <Text style={styles.ticketDescription}> Priority:  </Text><List.Item title={rowData.priority} />
                                            <Text style={styles.ticketDescription}> Location:  </Text><List.Item title={rowData.location} />
                                            <Text style={styles.ticketDescription}> Description:  </Text><List.Item title={rowData.desc} />
                                            <View>
                                                <View>
                                                    <Text style={styles.ticketDescription}> The Ticket is :  </Text>
                                                </View>
                                                <View>
                                                    <List.Item title={rowData.status} />
                                                </View>
                                            </View>
                                            <View style={{ flexDirection: 'row', justifyContent: 'space-between', marginLeft: 30, marginRight: 30 }}>
                                                <View style={styles.closedButtonBox}>
                                                    <TouchableOpacity onPress={() => ticketClosed()}>
                                                        <Text style={styles.closedButton}> Closed </Text>
                                                    </TouchableOpacity>
                                                </View>
                                                <View style={styles.closedButtonBox}>
                                                    <TouchableOpacity onPress={() => console.log("Pressed Resolved")}>
                                                        <Text style={styles.closedButton}> Resolved </Text>
                                                    </TouchableOpacity>
                                                </View>
                                            </View>

                                        </View>
                                    </List.Accordion>

                                ))

                            }

                        </List.AccordionGroup>
                    )}
                </View>
            </ScrollView>

server.js

const express = require('express')
const app = express()
const bodyParser = require('body-parser')
const mongoose = require('mongoose')
require('./User')

app.use(bodyParser.json())

const User = mongoose.model("user")

const mongoUrl = "MY_URL"

mongoose.connect(mongoUrl, {
    useNewUrlParser: true,
    useUnifiedTopology: true
})

mongoose.connection.on("connected", () => {
    console.log("Connected to Mongo")
})

mongoose.connection.on("error", (err) => {
    console.log("Error: ", err)
})

app.get('/', (req, res) => {
    User.find({}).then(data => {
        res.send(data)
    })
    .catch(err => {
        console.log(err)
    })
})
app.post('/closed', (req, res) => {
    User.findByIdAndUpdate(req.body.id, {
        name: req.body.name,
        request: req.body.request,
        subject: req.body.subject,
        location: req.body.location,
        category: req.body.category,
        priority: req.body.priority,
        desc: req.body.desc,
        status: req.body.status
    }).then(data => {
        console.log(data)
        res.send(data)
    })
    .catch(err => {
        console.log(err)
    })
})
app.post('/send-data', (req, res) => {
    const user = new User({
        name: req.body.name,
        request: req.body.request,
        subject: req.body.subject,
        category: req.body.category,
        priority: req.body.priority,
        desc: req.body.desc,
        location: req.body.location,
        status: req.body.status
    })
    user.save()
        .then(data => {console.log(data)
        res.send(data)
    }).catch(err => {
        console.log(err)
    })
})
app.listen(3000, () => {
    console.log("server running")
})

我的数据存储在 mongodb

_id:602cd535a41dba58d861ac9c
name:"ReactJS"
request:"Dhanjay"
subject:"Ticket stuck"
category:"IT"
priority:""
desc:"No reply"
location:"Pune"
status:"Open"
__v:0

_id:602cd5aca41dba58d861ac9d
name:"Access Restriction"
request:"Dhanjay"
subject:"No access"
category:"IT"
priority:""
desc:"SharePoint access"
location:"Pune"
status:"Open"
__v:0

这是我遇到的错误,服务器也发送空值:

[Unhandled promise rejection: SyntaxError: JSON Parse error: Unexpected EOF]
* [native code]:null in parse
- node_modules\react-native\node_modules\promise\setimmediate\core.js:37:13 in tryCallOne
- node_modules\react-native\node_modules\promise\setimmediate\core.js:123:24 in setImmediate$argument_0
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:130:14 in _callTimer
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:181:14 in _callImmediatesPass
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:441:30 in callImmediates
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:387:6 in __callImmediates
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:135:6 in __guard$argument_0
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10 in __guard
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:134:4 in flushedQueue
* [native code]:null in flushedQueue
* [native code]:null in invokeCallbackAndReturnFlushedQueue

它无法从多个 ID 中识别单个 ID,因此我只传递了具有特定 ID 的项目的单个值来更改该记录。

AllTicketScreen.js

ticketClosed = (_id, subject, name, request, category, priority, location, desc) => {
        fetch("http://ded02c8bed11.ngrok.io/closed", {
            method: "POST",
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({
                id: _id,
                name: name,
                request: request,
                subject: subject,
                category: category,
                priority: priority,
                desc: desc,
                location: location,
                status: "Closed"
            })
        })
        .then(res => res.json())
        .then(data => {
            navigation.navigate("Home")
        })
        .catch(err => {
            console.log("Error occurred: " + err);
        })
    }

JSX

<View style={styles.closedButtonBox}>
<TouchableOpacity onPress={() => ticketClosed(rowData._id, rowData.subject, rowData.name, rowData.request, rowData.category, rowData.priority, rowData.location, rowData.desc)}>
<Text style={styles.closedButton}> Closed </Text>
</TouchableOpacity>
</View>